SQL IN operator is used to check if a value is present in a given list a result list returned by sub quarries.
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.
- The IN operator checks a value with in a set of values and retrieve the rows from the table which are matching.
- IN condition can help to reduce multiple OR conditions in a Select statement, Insert statement, Update statement and Delete statement .
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’.
SELECT TITLE,AUTHORFIRSTNAME,AUTHORLASTNAME FROM BOOKS WHERE AUTHORLASTNAME IN (‘kalka’,’MEYER’,’AUSTEN’);
|PRIDE AND PREJUDICE||JANE||AUSTEN|