TheDeveloperBlog.com

Home | Contact Us

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

MySQL IN Condition

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

<< Back to MYSQL

MySQL IN Condition

The MySQL IN condition is used to reduce the use of multiple OR conditions in a SELECT, INSERT, UPDATE and DELETE statement.

Syntax:

expression IN (value1, value2, .... value_n);

Parameters

expression: It specifies a value to test.

value1, value2, ... or value_n: These are the values to test against expression. If any of these values matches expression, then the IN condition will evaluate to true. This is a quick method to test if any one of the values matches expression.

MySQL IN Example

Consider a table "officers", having the following data.

MySQL IN Condition

Execute the following query:

SELECT *
FROM officers
WHERE officer_name IN ('Ajeet', 'Vimal', 'Deepika');

Output:

MySQL IN Condition

Let's see why it is preferred over OR condition:

Execute the following query:

SELECT *
FROM officers
WHERE officer_name = 'Ajeet'
OR officer_name = 'Vimal'
OR officer_name = 'Deepika';

Output:

MySQL IN Condition

It also produces the same result. So IN condition is preferred over OR condition because it has minimum number of codes.


Next TopicMySQL ANY




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