TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

MySQL LIKE Condition

MySQL LIKE Condition example with examples on CRUD, insert statement, select statement, update statement, delete statement, use database, keys, joins etc.

<< Back to MYSQL

MySQL LIKE condition

In MySQL, LIKE condition is used to perform pattern matching to find the correct result. It is used in SELECT, INSERT, UPDATE and DELETE statement with the combination of WHERE clause.

Syntax:

expression LIKE pattern [ ESCAPE 'escape_character' ]

Parameters

expression: It specifies a column or field.

pattern: It is a character expression that contains pattern matching.

escape_character: It is optional. It allows you to test for literal instances of a wildcard character such as % or _. If you do not provide the escape_character, MySQL assumes that "\" is the escape_character.

MySQL LIKE Examples

1) Using % (percent) Wildcard:

Consider a table "officers" having the following data.

MySQL LIKE Condition 1

Execute the following query:

 SELECT officer_name
FROM officers
WHERE address LIKE 'Luck%';

Output:

MySQL LIKE Condition 2

2) Using _ (Underscore) Wildcard:

We are using the same table "officers" in this example too.

Execute the following query:

    
 SELECT officer_name
 FROM officers
 WHERE address LIKE 'Luc_now';

Output:

MySQL LIKE Condition 3

3) Using NOT Operator:

You can also use NOT operator with MySQL LIKE condition. This example shows the use of % wildcard with the NOT Operator.

Consider a table "officers" having the following data.

MySQL LIKE Condition 4

Execute the following query:

SELECT officer_name
FROM officers
WHERE address NOT LIKE 'Luck%';

Output:

MySQL LIKE Condition 5

Note: In the above example, you can see that the addresses NOT LIKE 'Luck%' are only shown.


Next TopicMySQL IN Condition




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf