SQL IN Operator

The SQL IN Operator is used to check to specified multiple matche values in a WHERE or HAVING clause, you can also use AND or OR operator for multiple WHERE or HAVING condition.

  • The IN Operator is a logical operator then the all values must have the same type of the column.
  • IN Operator return the value 1 when the search value present OTHERWISE it return 0 (Zero).

IN Operator Syntax

SELECT  column_name(s)
FROM table_name
WHERE column_name IN (value_1, value_2, value_3, .....);

Other IN Operator Syntax

SELECT  column_name(s)
FROM table_name
WHERE column_name IN (SELECT Statement);

EXAMPLE: IN Operator

Student Table

A table of student records, the name of table is "Student", and the name of columns are [ROLL_NO, STUDENT_NAME, ADDRESS, MOBILE_NO, AGE, and BRANCH]:

ROLL_NO STUDENT_NAME ADDRESS MOBILE_NO AGE BRANCH
1 Mohit Sharma Delhi XXXXXXXX87 20 IT
2 Pooja Pandit Kolkata XXXXXXXX34 18 CSE
3 Priya Pandey Delhi XXXXXXXX62 19 EEE
4 Mohit Kumar Jha Allahabad U.P XXXXXXXX87 20 ECE
5 Shevani Shree Noida U.P XXXXXXXX51 17 IT
6 Badshah Mumbai XXXXXXXX02 20 Civil
7 Viki Mohan Pune XXXXXXXX72 19 CSE
8 Sona Kaur Indor M.P XXXXXXXX81 22 ME

IN Operator

SELECT  *
FROM Student
WHERE BRANCH IN (IT, CSE);

Result Look Like

ROLL_NO STUDENT_NAME ADDRESS MOBILE_NO AGE BRANCH
1 Mohit Sharma Delhi XXXXXXXX87 20 IT
2 Pooja Pandit Kolkata XXXXXXXX34 18 CSE
5 Shevani Shree Noida U.P XXXXXXXX51 17 IT
7 Viki Mohan Pune XXXXXXXX72 19 CSE

NOT IN Operator

SELECT  *
FROM Student
WHERE BRANCH NOT IN (IT, CSE);

Result Look Like

ROLL_NO STUDENT_NAME ADDRESS MOBILE_NO AGE BRANCH
3 Priya Pandey Delhi XXXXXXXX62 19 EEE
4 Mohit Kumar Jha Allahabad U.P XXXXXXXX87 20 ECE
6 Badshah Mumbai XXXXXXXX02 20 Civil
8 Sona Kaur Indor M.P XXXXXXXX81 22 ME

Policy

GDATAMART.COM is optimized for learning & job information; The users try to improve your knowledge and practical experience through this site but we cannot warrant full correctness of all content... Learn More → | Sitemap →

© 2020 GDATAMART | All Rights Reserved