Let us first create a −
mysql> create table DemoTable1418 -> ( -> EmployeeCode text -> ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1418 values('EMP-2110/Carol'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1418 values('EMP-1900/David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1418 values('EMP-2345/Mike'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select −
mysql> select * from DemoTable1418;
This will produce the following output −
+----------------+ | EmployeeCode | +----------------+ | EMP-2110/Carol | | EMP-1900/David | | EMP-2345/Mike | +----------------+ 3 rows in set (0.00 sec)
Here is the query to use SELECT LEFT in MySQL to fetch the above records before slash −
mysql> select left(EmployeeCode,8) from DemoTable1418;
This will produce the following output −
+----------------------+ | left(EmployeeCode,8) | +----------------------+ | EMP-2110 | | EMP-1900 | | EMP-2345 | +----------------------+ 3 rows in set (0.00 sec)