This SQLite post explains how to use the SQLite OR condition with syntax and examples.
The SQLite OR Condition is used to test two or more conditions where records are returned when any one of the conditions are met. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.
The syntax for the OR Condition in SQLite is:
Any of the conditions that must be met for the records to be selected.
The first SQLite OR condition example that we'll take a look at involves a SELECT statement with 2 conditions:
This SQLite OR condition example would return all employees that have a last_name of 'Smith' or an employee_id of 5. Because the * is used in the SELECT statement, all fields from the employees table would appear in the result set.
The next SQLite OR example looks at a SELECT statement with 3 conditions. If any of these conditions is met, the record will be included in the result set.
This SQLite OR condition example would return all last_name and first_name values from the employees table where the last_name is 'Smith', the employee_id is 5, or the first_name is 'Sarah'. If any of these conditions is met, the record will be included in the result set.
The SQLite OR condition can be used in the INSERT statement.
For example:
This SQLite OR example would insert into the contacts table, all employee_id, last_name, and first_name values from the employees table where the employee_id is either 1 or 2.
The SQLite OR condition can be used in the UPDATE statement.
For example:
This SQLite OR condition example would update all department values in the employees table to 'Accounting' where the last_name is 'Smith' or the first_name is 'Jane'.
The SQLite OR condition can be used in the DELETE statement.
For example:
This SQLite OR condition example would delete all employees from the employees table where the employee_id is 1 or the first_name is 'Joanne'.