SQL IN operator is used to check if a value is present in a given list a result list returned by sub quarries.

For example,

Lest say, BOOKS table contains books written by different authors named from A to Z. We want to retrieve list of books written by only 3 authors e.g. A, B and C authors.

Then we can do this using SQL IN operators. We will see the example query below of the page.

POINTS:

SQL IN Operator Syntax

Expression IN (value1, value2, value3….);

IN operator Example

Get the list from the Books table where the AUTHORSLASTNAME is either  ‘kalka’  or  ‘MEYER’ or  ‘AUSTEN’.

Query
SELECT TITLE,AUTHORFIRSTNAME,AUTHORLASTNAME FROM BOOKS WHERE AUTHORLASTNAME IN (‘kalka’,’MEYER’,’AUSTEN’);

Output:

TITLEAUTHORFIRSTNAMEAUTHORLASTNAME
The CastleFranzKalka
TWILIGHTSTEPHENIEMEYER
PRIDE AND PREJUDICEJANEAUSTEN

Related Posts