Can we set a single value in MySQL SELECT IN()?


Yes, we can set a single value with IN() in MySQL. Let us first create a table−

mysql> create table DemoTable
   -> (
   -> FirstName varchar(20)
   -> );
Query OK, 0 rows affected (0.65 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('Chris');
Query OK, 1 row affected (0.42 sec)
mysql> insert into DemoTable values('David');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('Mike');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('Bob');
Query OK, 1 row affected (0.08 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output:

+-----------+
| FirstName |
+-----------+
| Chris     |
| David     |
| Mike      |
| Bob       |
+-----------+
4 rows in set (0.00 sec)

Following is the query to set a single value with MySQL IN −

mysql> select *from DemoTable where FirstName IN('Mike');

This will produce the following output:

+-----------+
| FirstName |
+-----------+
| Mike      |
+-----------+
1 row in set (0.00 sec)

Updated on: 18-Dec-2019

231 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements