Select * but ignore displaying results containing a specific character in MySQL


To ignore a specific character, use NOT LIKE operator. Let us first create a table −

mysql>  create table DemoTable1366
    -> (
    -> CountryName varchar(20)
    -> );
Query OK, 0 rows affected (0.77 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1366 values('AUS');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable1366 values('UK');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable1366 values('US');
Query OK, 1 row affected (0.10 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1366;

This will produce the following output −

+-------------+
| CountryName |
+-------------+
| AUS         |
| UK          |
| US          |
+-------------+
3 rows in set (0.00 sec)

Here is the query to ignore displaying results containing a specific character −

mysql> select * from DemoTable1366 where CountryName NOT LIKE '%S';

This will produce the following output −

+-------------+
| CountryName |
+-------------+
| UK          |
+-------------+
1 row in set (0.00 sec)
raja
Published on 08-Nov-2019 11:02:00
Advertisements