SQL IN

SQL IN can be used to to have multiple values with WHERE clause .

Syntax

SELECT * FROM table_name WHERE column_name IN (val1,val2)

MySQL Table – users

+—-+——+
| id | name |
+—-+——+
|  1 | PHP  |
|  2 | JS   |
|  3 | HTML |
|  5 | ASP  |
+—-+——+

Example

mysql> SELECT * FROM users WHERE name IN(‘PHP’,’JS’);
+—-+——+
| id | name |
+—-+——+
|  1 | PHP  |
|  2 | JS   |
+—-+——+
2 rows in set (0.01 sec)


Share