
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Use MySQL LIKE and NOT LIKE to display similar results?
Let us first create a table −
mysql> create table DemoTable -> ( -> CollegeCode varchar(100) -> ); Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Col.1995.01.21'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Col.2016.11.22'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(null); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Col.2018.12.01'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Col.2019.03.12'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+----------------+ | CollegeCode | +----------------+ | Col.1995.01.21 | | Col.2016.11.22 | | NULL | | Col.2018.12.01 | | Col.2019.03.12 | +----------------+ 5 rows in set (0.00 sec)
Following is the query for MySQL LIKE −
mysql> select *from DemoTable where CollegeCode LIKE '%Col%' or CollegeCode is NULL;
Output
This will produce the following output −
+----------------+ | CollegeCode | +----------------+ | Col.1995.01.21 | | Col.2016.11.22 | | NULL | | Col.2018.12.01 | | Col.2019.03.12 | +----------------+ 5 rows in set (0.00 sec)
Following is the query for NOT LIKE −
mysql> select *from DemoTable where CollegeCode NOT LIKE '%College%' or CollegeCode is NULL;
Output
This will produce the following output −
+----------------+ | CollegeCode | +----------------+ | Col.1995.01.21 | | Col.2016.11.22 | | NULL | | Col.2018.12.01 | | Col.2019.03.12 | +----------------+ 5 rows in set (0.00 sec)
- Related Articles
- How to use MySQL LIKE to create a search system and display results on the basis of keyword?
- How Are MySQL INSTR() and LIKE operator similar?
- What is the use of MySQL NOT LIKE operator?
- Display different variables in MySQL using LIKE?
- How to query MongoDB similar to “like” ?
- Display specific table names with MySQL LIKE Operator
- Can we use LIKE and OR together in MySql?
- Create a temporary table similar to a regular table with MySQL LIKE
- How to use user variables in MySQL LIKE clause?
- How can I achieve similar result like using a loop in MySQL WHERE clause to display only alternate ID records?
- MySQL LIKE IN()?
- MYSQL: Can you pull results that match like 3 out of 4 expressions?
- What is the use of MySQL SOUNDS LIKE operator?
- Why in MySQL, we cannot use arithmetic operators like ‘=’, ‘
- Can we use “LIKE concat()” in a MySQL query?

Advertisements