Your Ad Here
SQL Basic

Bookmark and Share
SQL IN Keyword

sql IN Keyword is nothing but it returns the result which is match for the given value inside the parenthesis. Syntax for sql IN Keyword:

SELECT "column_name"
FROM "table_name"
WHERE "column_name" IN ('value1')

Also we are check multiple values in single column. Syntax for check multiple values:

SELECT "column_name"
FROM "table_name"
WHERE "column_name" IN ('value1', 'value2', ... ,'valueN')

The number of values in the parenthesis can be one or more as required, with each values separated by comma. Values can be numerical or characters or both. If there is only one value inside the parenthesis, this command is equivalent to

WHERE "column_name" = 'value1'

If there is multiple value inside the parenthesis, this commend is equivalent to

WHERE
"column_name" = 'value1' OR
"column_name" = 'value2' OR
.
.
.
"column_name" = 'valueN'

let we explain the SQL IN keyword with this below example. Table name is price_information

article_name pirchase_price margin selling_price
4GB Pendrive $12 $1 $13
8GB Pendrive $15 $2 $17
12GB Pendrive $16 $2 $18
16GB Pendrive $20 $2 $22
 
Example 1:

Executed Query:
SELECT *
FROM price_information
WHERE article_name IN ('4GB Pendrive')

Result:
article_name pirchase_price margin selling_price
4GB Pendrive $12 $1 $13

Description:
The query will give the result which article_name is match with 4GB Pendrive. Also the below query also gives the same result.

SELECT * FROM price_information WHERE article_name = '4GB Pendrive'
 
Example 2:

Executed Query:
SELECT *
FROM price_information
WHERE article_name IN ('4GB Pendrive','16GB Pendrive')

Result:
article_name pirchase_price margin selling_price
4GB Pendrive $12 $1 $13
16GB Pendrive $20 $2 $22

Description:
The query will give the result which article_name column is match with 4GB Pendrive or 16GB Pendrive. Also the below query also gives the same result.

SELECT *
FROM price_information
WHERE article_name = '4GB Pendrive'
OR article_name = '16GB Pendrive'


Today's Deal