
- 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
Passing an array to a query using WHERE clause in MySQL?
We can pass an array with the help of where IN clause. Let us first create a new table for our example.
mysql> create table PassingAnArrayDemo -> ( -> id int, -> Firstname varchar(100) -> ); Query OK, 0 rows affected (1.60 sec)
Let us now insert records.
mysql> insert into PassingAnArrayDemo values(1,'John'),(2,'Carol'),(3,'Smith'),(4,'Bob'),(5,'Johnson'),(6,'David'),(7,'Sam'),(8,'Jessica'); Query OK, 8 rows affected (0.32 sec) Records: 8 Duplicates: 0 Warnings: 0
To display all records.
mysql> select *from PassingAnArrayDemo;
The following is the output.
+------+-----------+ | id | Firstname | +------+-----------+ | 1 | John | | 2 | Carol | | 3 | Smith | | 4 | Bob | | 5 | Johnson | | 6 | David | | 7 | Sam | | 8 | Jessica | +------+-----------+ 8 rows in set (0.00 sec)
The following is the syntax to send an array parameter with the help of where IN clause.
mysql> SELECT * -> FROM PassingAnArrayDemo where id IN(1,3,6);
The following is the output.
+------+-----------+ | id | Firstname | +------+-----------+ | 1 | John | | 3 | Smith | | 6 | David | +------+-----------+ 3 rows in set (0.04 sec)
- Related Articles
- Using LIKE clause twice in a MySQL query
- Get all results using WHERE clause in MySQL?
- Using the entire expression in MySQL WHERE clause?
- How can we simulate the MySQL INTERSECT query having WHERE clause?
- How to update multiple rows using single WHERE clause in MySQL?
- MySQL to Implementing OR operator in a WHERE clause?
- How to add a where clause in a MySQL Insert statement?
- Delete a specific record from a MySQL table by using AND in WHERE clause
- Get current year in MySQL WHERE clause?
- How to use MySQL VIEW with WHERE clause?
- Set an alternative of WHERE clause for each SELECT field in MySQL
- Update with multiple values in MySQL WHERE clause
- MySQL UNION SELECT and IN clause in a single query
- Passing an array to a C++ function
- How to use MySQL Date functions with WHERE clause?

Advertisements