Summary: in this tutorial, you will learn how to use the SQLite IN operator to determine whether a value matches any value in a list of values or a result of a subquery.
Introduction to the SQLite IN operator
The SQLite IN operator determines whether a value matches any value in a list or a subquery. The syntax of the IN operator is as follows:
expression [NOT] IN (value_list|subquery);Code language: SQL (Structured Query Language) (sql)The expression can be any valid expression or a column of a table.
A list of values is a fixed value list or a result set of a single column returned by a subquery. The returned type of expression and values in the list must be the same.
The IN operator returns true or false depending on whether the expression matches any value in a list of values or not. To negate the list of values, you use the NOT IN operator.
SQLite IN operator examples
We will use the Tracks table from the sample database for the demonstration.
The following statement uses the IN operator to query the tracks whose media type id is 1 or 2.
SELECT
TrackId,
Name,
Mediatypeid
FROM
Tracks
WHERE
MediaTypeId IN (1, 2)
ORDER BY
Name ASC;Code language: SQL (Structured Query Language) (sql)