Decomposing or Combining Strings
mysql>
mysql> CREATE TABLE mytable
-> (
-> name VARCHAR(20)
-> );
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO mytable (name)
-> VALUES
-> ('copper'),
-> ('gold'),
-> ('iron'),
-> ('lead'),
-> ('mercury'),
-> ('platinum'),
-> ('silver'),
-> ('tin')
-> ;
Query OK, 8 rows affected (0.00 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql>
mysql> SELECT * FROM mytable;
+----------+
| name |
+----------+
| copper |
| gold |
| iron |
| lead |
| mercury |
| platinum |
| silver |
| tin |
+----------+
8 rows in set (0.00 sec)
mysql>
mysql>
mysql> SELECT name, LEFT(name,2), MID(name,3,1), RIGHT(name,3) FROM mytable;
+----------+--------------+---------------+---------------+
| name | LEFT(name,2) | MID(name,3,1) | RIGHT(name,3) |
+----------+--------------+---------------+---------------+
| copper | co | p | per |
| gold | go | l | old |
| iron | ir | o | ron |
| lead | le | a | ead |
| mercury | me | r | ury |
| platinum | pl | a | num |
| silver | si | l | ver |
| tin | ti | n | tin |
+----------+--------------+---------------+---------------+
8 rows in set (0.00 sec)
mysql>
mysql> drop table mytable;
Query OK, 0 rows affected (0.00 sec)
Related examples in the same category