
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- SELECT WHERE IN null in MySQL?
- MySQL Select where values IN List string?
- MySQL select query with multiple WHERE?
- SELECT where row value contains string in MySQL?
- MySQL - SELECT … WHERE id IN (..) order with particular column?
- MySQL Select where timestamp is in the current hour?
- SELECT a row by subtracting dates in WHERE in MySQL?
- MySQL Select where value exists more than once
- Can I use two where clauses like “SELECT * FROM table WHERE condition1 and condition2” in MySQL?
- Select from table where value does not exist with MySQL?
- Set an alternative of WHERE clause for each SELECT field in MySQL
- What would happen if we run SELECT WHERE columnName = zero in MySQL?
- MySQL SELECT products WHERE 'average price per product' < value?
- How to select data in MySQL where a field has a minimum value?
- Select MySQL rows where column contains same data in more than one record?

Advertisements