SQLite OR
To make multiple comparisons with different operators in the same statement, the SQLite OR clause is used. It is generally used with SELECT, UPDATE and DELETE statements. In the case of OR operation, if any of the given condition is true, the complete condition is considered true. It is always used with the WHERE Clause.
Syntax:
SELECT column_1, column_2, column_N FROM table_name WHERE condition_1 OR condition_2...OR condition_N;
Example:
TEACHERS Table:
ID | NAME | AGE | SUBJECT |
1 | Jim | 27 | English |
2 | John | 30 | Geology |
3 | Watson | 28 | French |
4 | Holmes | 40 | Chemistry |
5 | Tony | 35 | Physics |
SELECT * FROM TEACHERS WHERE ID > 2 OR AGE >= 30; |
Output:
ID | NAME | AGE | SUBJECT |
2 | John | 30 | Geology |
3 | Watson | 28 | French |
4 | Holmes | 40 | Chemistry |
5 | Tony | 35 | Physics |
Explanation:
The “TEACHERS” is an already existing table. Here we are selecting those rows of the table where either the value in the ID column is greater than 2 or the value in the AGE column is greater than or equal to 30 or where both the conditions are true.