This SQLite post explains how to use the SQLite IN condition with syntax and examples.
The SQLite IN condition is used to help reduce the need to use multiple OR conditions in a SELECT, INSERT, UPDATE, or DELETE statement.
The syntax for the IN condition in SQLite is:
OR
A value to test.
The values to test against expression.
This is a SELECT statement whose result set will be tested against expression. If any of these values matches expression, then the IN condition will evaluate to true.
Let's look at a SQLite IN condition example using character values.
The following is a SQLite SELECT statement that uses the IN condition to compare character values:
This SQLite IN condition example would return all rows from the employees table where the first_name is either 'Sarah', 'Jane', or 'Heather'. Because the * is used in the SELECT, all fields from the employees table would appear in the result set.
The above IN example is equivalent to the following SELECT statement:
As you can see, using the SQLite IN condition makes the statement easier to read and more efficient.
Next, let's look at a SQLite IN condition example using numeric values.
For example:
This SQLite IN condition example would return all employees where the employee_id is either 1, 2, 3, or 4.
The above IN example is equivalent to the following SELECT statement:
Finally, let's look at an IN condition example using the NOT operator.
For example:
This SQLite IN condition example would return all rows from the employees table where the first_name is not Sarah or Jessica. Sometimes, it is more efficient to list the values that you do not want, as opposed to the values that you do want.