Text manipulation of strings containing “The ”? in MySQL


You can use ORDER BY TRIM(). Let us first create a table −

mysql> create table DemoTable
   -> (
   -> Title text
   -> );
Query OK, 0 rows affected (1.09 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('MongoDB is a no SQL database');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values('The MySQL is a relational database');
Query OK, 1 row affected (0.22 sec)
mysql> insert into DemoTable values('The Java language is good');
Query OK, 1 row affected (0.35 sec)
mysql> insert into DemoTable values('Python is good language');
Query OK, 1 row affected (0.17 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+----------------------------------+
| Title                            |
+----------------------------------+
| MongoDB is a no SQL database     |
|The MySQL is a relational database|
| The Java language is good        |
| Python is good language          |
+----------------------------------+
4 rows in set (0.00 sec)

Here is the query for text manipulation of strings containing “The ” −

mysql> select *from DemoTable
   -> order by trim(leading 'The ' from Title);

This will produce the following output −

+----------------------------------+
| Title                            |
+----------------------------------+
| The Java language is good        |
| MongoDB is a no SQL database     |
|The MySQL is a relational database|
| Python is good language          |
+----------------------------------+
4 rows in set (0.00 sec)

Updated on: 17-Dec-2019

124 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements