IN Operator Tutorial in php
SELECT with IN Operator Syntax :
SELECT column1, column2, column3... FROM table_name WHERE column_name IN (value1, value2, value3...);
SELECT with NOT IN Operator Syntax :
SELECT column1, column2, column3...FROM table_name WHERE column_name NOT IN (value1, value2, value3...);
If we want to select record whose age is 18 OR 21 using IN Operator from table name "personal" then we can apply below Sql query as shown below :
SELECT * FROM personal WHERE age IN (18, 21);
If we want to select record whose age is 18 OR 21 OR 19 using IN Operator from table name "personal" then we can apply below sql query as shown below :
SELECT * FROM personal WHERE age IN (18, 21,19);
Usage of NOT IN Operator as shown below :
If we want to select record whose age is except 18 OR 21 OR 19 using NOT IN Operator from table name "personal" then we can apply below sql query as shown below :
SELECT * FROM personal WHERE age NOT IN (18,21,19);
If we want to select records whose city is "Ahmedabad" OR ''Dahod" using IN Operator from table name "personal" then we can apply below sql query as shown below :
SELECT * FROM personal WHERE city IN ("Ahmedabad", "Dahod");
If we want to select records whose city is NOT "Ahmedabad" OR NOT "Dahod" OR NOT "Agra" using NOT IN Operator from table name "personal" then we can apply sql query as shown below :
SELECT * FROM personal WHERE city NOT IN ("Ahmedabad", "Dahod", "Agra");
If we want to select records whose id is 1 OR 2 OR 10 using IN Operator from table name "personal" then we can apply sql query as shown below :
SELECT * FROM personal WHERE id IN (1,2,10);
WHEN WE WANT TO CHECK MULTIPLE RECORDS IN SINGLE COLUMN AT THAT TIME "IN"
OPERATOR IS USED
Comments
Post a Comment