IN Operator in SQL
The IN operator allows you to specify multiple values in a WHERE clause.
Syntax :-
Example :-First of all we create the table named is tblStudentRecord and insert some records as shown in below.
IN Operator Example :- The following SQL statement selects all records of students from tblStudentRecord table with a Name of "Santosh kumar singh" or "Er. Reena Tanti":
Syntax :-
SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...)
Example :-First of all we create the table named is tblStudentRecord and insert some records as shown in below.
CREATE TABLE tblStudentRecord ( Name varchar(100), Rollno int primary key, Branch varchar(30),Email varchar(100),Address varchar(200) ) Insert some records :- INSERT INTO tblStudentRecord VALUES('Santosh kumar singh',1001,'Information Technology','sa@gmail.com','A-3033') INSERT INTO tblStudentRecord VALUES('Er. Reena Tanti',1002,'ECE','err@gmail.com','T-387, Gaya') INSERT INTO tblStudentRecord VALUES('Chandan kumar',1003,'CSE','chn@gmail.com','Gaya') INSERT INTO tblStudentRecord VALUES('Nand kishor kumar',1004,'BCA','nk@gmail.com','A-3033,Darbhanga') INSERT INTO tblStudentRecord VALUES('Abhinav kumar',1005,'MCA','ab@gmail.com','H-837') INSERT INTO tblStudentRecord VALUES('Santosh kumar singh',1006,'CSE','santosh@gmail.com','A-3031') INSERT INTO tblStudentRecord VALUES('Neha sharma',1007,'MCA','h@gmail.com','D-34,Patna') INSERT INTO tblStudentRecord VALUES('Pooja',1008,'ECE','pr@gmail.com','A-90, Jaipur, Rajashthan') INSERT INTO tblStudentRecord VALUES('Jaya Laxmi',1009,'CSE','jl@gmail.com','Kerla') INSERT INTO tblStudentRecord VALUES('Pakaj Kumar',1010,'BCA','pk@gmail.com','A-30,Darbhanga,Bihar') INSERT INTO tblStudentRecord VALUES('Abhinav kumar',1011,'ME','ab1@gmail.com','K-837') INSERT INTO tblStudentRecord VALUES('Suneeta',1012,'MCA','su@gmail.com','UP') INSERT INTO tblStudentRecord VALUES('Suman Kumar',1013,'IT','sk@gmail.com','Block-T,Darbhanga') INSERT INTO tblStudentRecord VALUES('Ajay kumar',1014,'ECE','aj@gmail.com','D-89')
IN Operator Example :- The following SQL statement selects all records of students from tblStudentRecord table with a Name of "Santosh kumar singh" or "Er. Reena Tanti":
SELECT * FROM tblStudentRecord WHERE Name IN ('Santosh kumar singh','Er. Reena Tanti')