This article will see how to select multiple values using the IN and OR operators in MySQL WHERE clause.

Table of Contents:-

Let us get started by making the sample data. We will be creating a table sale_details followed by inserting a few rows into it.

# create table sale_details
CREATE TABLE sale_details (
    id INT ,
    sale_person_id VARCHAR(255) ,
    sale_person_name VARCHAR(255),
    no_products_sold INT,
    sales_department VARCHAR(255)
);
#inserting into sale_details
INSERT INTO sale_details (id, sale_person_id, sale_person_name, no_products_sold, sales_department) 
 VALUES(1,"sd1","Henry",2000,"Kitchen Essentials"),
 (2,"sd1","Henry",5000,"Apparels"),
 (3,"sd1","Henry",40,"Medicines"),
 (4,"sd2","Richa",3000,"Kitchen Essentials"),
 (5,"sd2","Richa",500,"Apparels"),
 (6,"sd2","Richa",50,"Medicines"),
 (7,"sd3","Ved",100,"Kitchen Essentials"),
 (8,"sd3","Ved",150,"Apparels"),
 (9,"sd3","Ved",1000,"Medicines"),
 (10,"sd4","George",600,"Kitchen Essentials"),
 (11,"sd4","George",1200,"Apparels"),
 (12,"sd4","George",200,"Medicines");

To view the snapshot of the sale_details table, execute:

SELECT * FROM sale_details;

Output:-

image1: sale_details

MySQL select multiple values using IN operator

This section will see how to use IN operator to select multiple values in MySQL queries.

Example: Select all the columns from the sale_details table where sale_person_id is sd1 or sd2.

SELECT * FROM sale_details WHERE sale_person_id IN ( "sd1" , "sd2");

Output:-

image_2

The output in image_2 shows that records with sale_person_id values sd1, sd2 are selected.

MySQL select multiple values using OR operator

This section will see how to use OR operator to select multiple values in MySQL queries.

Example: Select all the columns from the sale_details table where sale_person_id is sd1 or sd2.

SELECT * FROM sale_details WHERE sale_person_id = "sd1" OR sale_person_id =  "sd2";

Output:-

image_3

The output in image_3 shows that records with sale_person_id values sd1, sd2 are selected.

MySQL select multiple values using combination of IN and OR operator

This section will see how to use OR and IN operator combinations to select multiple values in MySQL queries.

Example: Select all the columns from the sale_details table where sale_person_id is sd1 or sd2 or sale_person_name is George.

SELECT * FROM sale_details WHERE sale_person_id IN ( "sd1" , "sd2") OR sale_person_name ="George";

Output:-

image_4

The output in image_4 shows that the records with either sale_person_id sd1sd2, or with sale_person_name George are selected.

READ MORE:

We hope this article helped you with MySQL queries selecting multiple values. Good Luck!!!