This SQLite post explains how to use the SQLite WHERE clause with syntax and examples.
The SQLite WHERE clause is used to filter the results from a SELECT, INSERT, UPDATE, or DELETE statement.
The syntax for the WHERE clause in SQLite is:
The conditions that must be met for records to be selected.
It is difficult to explain the syntax for the SQLite WHERE clause, so let's look at some examples.
In this SQLite WHERE clause example, we've used the WHERE clause to filter our results from the employees table. The SELECT statement above would return all rows from the employees table where the first_name is 'Sarah'. Because the * is used in the SELECT, all fields from the employees table would appear in the result set.
This SQLite WHERE clause example uses the WHERE clause to define multiple conditions. In this case, this SELECT statement uses the AND Condition to return all employees that have a last_name of 'Jones' and a favorite_website of 'AODBA.com'.
This SQLite WHERE clause example uses the WHERE clause to define multiple conditions, but instead of using the AND Condition, it uses the OR Condition. In this case, this SELECT statement would return all employee_id, last_name, and first_name values from the employees table where the employee_id is 1 or 2.
This SQLite WHERE clause example uses the WHERE clause to define multiple conditions, but it combines the AND Condition and the OR Condition. This example would return all employees that have a last_name of 'Smith' and a first_name of 'Jane' as well as all employees that have an employee_id of 1.
The parentheses determine the order that the AND and OR conditions are evaluated. Just like you learned in the order of operations in Math class!
This SQLite WHERE clause example uses the WHERE clause to join multiple tables together in a single SELECT statement. This SELECT statement would return all employee_id and title values where there is a matching record in the employees and positions tables based on position_id.
Although you can use the older syntax to join your tables using the WHERE clause, it is more appropriate to use a proper INNER JOIN as follows:
Learn more about SQLite joins.