What is the correct syntax for NOT LIKE in MySQL?

MySQLMySQLi Database

The following is the correcrt syntax for NOT LIKE in MySQL:

SHOW TABLES WHERE `TABLES_IN_yourDatabaseName` NOT LIKE ‘yourTableName%’;

To understand the above syntax, we will use the database SAMPLE which has some tables. First, we will display all tables of sample database. After that we will use the above syntax.

The query is as follows to display all tables. First switch the database to SAMPLE using USE command:

mysql> USE SAMPLE;
Database changed

Display all tables from the database. The query is as follows:

mysql> show tables;

The following is the output:

+--------------------------+
| Tables_in_sample         |
+--------------------------+
| blobsizedemo             |
| insert_prevent           |
| insertrecord_selecttable |
| insertrecordprevent      |
| mytable                  |
| newlinedemo              |
| notequaloperator         |
| sumofeverydistinct       |
| yourtable                |
+--------------------------+
9 rows in set (0.00 sec)

Now you can use above syntax to check all table names which does not have the text “insert” in it. The query is as follows:

mysql> show tables where `TABLES_IN_sample` NOT LIKE 'insert%';

The following is the output:

+--------------------+
| Tables_in_sample   |
+--------------------+
| blobsizedemo       |
| mytable            |
| newlinedemo        |
| notequaloperator   |
| sumofeverydistinct |
| yourtable          |
+--------------------+
6 rows in set (0.00 sec)
raja
Published on 27-Feb-2019 11:37:22
Advertisements