Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Using MySQL IN() for some column values with underscore
Let us first create a table −
mysql> create table DemoTable1363 -> ( -> StudentId varchar(20) -> ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1363 values('901');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable1363 values('702');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable1363 values('901_John_Doe');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1363 values('1001_Carol_Taylor');
Query OK, 1 row affected (0.26 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1363;
This will produce the following output −
+-------------------+ | StudentId | +-------------------+ | 901 | | 702 | | 901_John_Doe | | 1001_Carol_Taylor | +-------------------+ 4 rows in set (0.00 sec)
Here is the MySQL query to implement IN() −
mysql> select * from DemoTable1363 where StudentId IN('702','1001');
This will produce the following output −
+-----------+ | StudentId | +-----------+ | 702 | +-----------+ 1 row in set (0.00 sec)
Advertisements
