
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
SELECT * WHERE var == [one of many alternatives] in MySQL?
Use IN() for select * where var== [one of many alternatives]. Let us first create a table −
mysql> create table DemoTable1624 -> ( -> ClientId int, -> ClientName varchar(20) -> ); Query OK, 0 rows affected (0.39 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1624 values(101,'Chris Brown'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1624 values(102,'David Miller'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1624 values(103,'John Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1624 values(104,'Carol Taylor'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1624 values(105,'Adam Smith'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1624;
This will produce the following output −
+----------+--------------+ | ClientId | ClientName | +----------+--------------+ | 101 | Chris Brown | | 102 | David Miller | | 103 | John Smith | | 104 | Carol Taylor | | 105 | Adam Smith | +----------+--------------+ 5 rows in set (0.00 sec)
Here is the query to implement SELECT * WHERE var == [one of many alternatives] −
mysql> select * from DemoTable1624 where ClientId in(101,102,104);
This will produce the following output −
+----------+--------------+ | ClientId | ClientName | +----------+--------------+ | 101 | Chris Brown | | 102 | David Miller | | 104 | Carol Taylor | +----------+--------------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- SELECT WHERE IN null in MySQL?
- Select MySQL rows where column contains same data in more than one record?
- MySQL query to select too many rows?
- MySQL select query with multiple WHERE?
- How to select a row where one of several columns equals a certain value in MySQL?
- One-to-Many or Many-to-One Relationship in DBMS
- MySQL Select where values IN List string?
- MySQL query to select column where value = one or value = two, value = three, etc?
- SELECT where row value contains string in MySQL?
- MySQL Select where value exists more than once
- MySQL Select where timestamp is in the current hour?
- Set an alternative of WHERE clause for each SELECT field in MySQL
- SELECT a row by subtracting dates in WHERE in MySQL?
- One-to-Many Relationship Model
- MySQL - SELECT … WHERE id IN (..) order with particular column?
Advertisements