EXISTS Condition


 

SQLite: EXISTS Condition

This SQLite tutorial explains how to use the SQLite EXISTS condition with syntax and examples.

 

Description:
The SQLite EXISTS condition is used in combination with a Subquery and is considered “to be met” if the Subquery returns at least one row. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.

 

Syntax:

 

Parameters or Arguments:

Subquery

A SELECT statement that usually starts with SELECT * rather than a list of expressions or column names.

Note: SQLite statements that use the EXISTS Condition in SQLite are very inefficient since the sub-query is RE-RUN for EVERY row in the outer query’s table. There are more efficient ways to write most queries, that do not use the EXISTS Condition.

 

Examples:
The following SQLite statement returns all records from the employee table where there is at least one record in the account table with the matching id.:

id name position hire_date
100 chiru developer 1/1/2014
101 arunesh manager 1/1/2012
102 naga Team Lead 1/1/2013
103 nithya developer 6/1/2013
104 jaya developer 1/1/2014
105 uma designer 1/1/2013
106 mathu research analyst 1/1/2013