Sqlite

SQLite IN Clause

SQLite IN Clause

Let’s learn about the SQLite IN clause. The SQLite IN clause specifies a range of values for a WHERE condition.

Syntax

It is commonly used in the WHERE clause to filter rows based on a specified set of values. The general syntax of the statement using the IN clause is as follows:

The syntax to display all the columns in the table:

SELECT *
FROM table_name
WHERE search_column IN (value1, value2,…,valueN);

To display selected columns:

SELECT column1, column2….columnN
FROM table_name
WHERE search_column IN (value1, value2,…,valueN);

The set in the IN clause is comma-separated list.

Example

In the below example, the query selects rows where the empno column values is in the specified set of values.

sqlite> SELECT * FROM emp
…> WHERE empno IN (2 , 4, 6);

SQLite IN Clause

Notice the query results are filtered to only those employees who empno that we specified in the IN clause.

If the set has non-existent values those values will not be displayed in the query results. This is becuase there are no rows in the table.

 

SQLite Tutorials

SQLite tutorials on this website:

https://www.testingdocs.com/sqlite-database-tutorials/