For this, use LEFT in MySQL. Let us first create a table −
mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Java database connectivity to MySQL database'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Python with django framework'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('C with data structure and algorithm'); Query OK, 1 row affected (0.33 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------------------------------------------+ | Title | +----------------------------------------------+ | Java database connectivity to MySQL database | | Python with django framework | | C with data structure and algorithm | +----------------------------------------------+ 3 rows in set (0.00 sec)
Following is the query to fetch some words from the left in MySQL −
mysql> select left(Title,10) as Title from DemoTable;
This will produce the following output −
+-----------------+ | Title | +-----------------+ | Java datab | | Python wit | | C with dat | +-----------------+ 3 rows in set (0.00 sec)