SQLite AND/OR operators
SQLite's AND and OR operators are used to compile multiple conditions to narrow down the data selected in a SQLite statement. These two operators are called concatenation operators.
These operators provide the possibility for multiple comparisons between different operators in the same SQLite statement.
AND Operator
AND operator allows the presence of multiple conditions in the WHERE clause of a SQL statement. When using the AND operator, the entire condition is true only if all conditions are true. For example, [condition1] AND [condition2] is true only if both condition1 and condition2 are true.
Syntax
The basic syntax of the AND operator with a WHERE clause is as follows:
FROM table_name
WHERE [condition1] AND [condition2]...AND [conditionN];
You can use the AND operator to combine N quantities of conditions. The action that a SQLite statement needs to perform is that, whether it is a transaction or a query, all conditions separated by AND must be true (TRUE).
Example
Assuming the COMPANY table has the following records:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------- ----------- ---------- ----------
1 " Paul " 32 " California 20000.0
2 " Allen 25 Texas 15000.0
3 Teddy 23 NORWAY 20000.0 ## 4 Mark 25 Rich-Mond 65000.0
5 David 27 TEXAS 85000.0
6 KIM 22 South-Hall 45000.0
7 Jamest on 10000.0
The following SELECT statement lists all records where AGE is greater than or equal to 25 and salary is greater than or equal to 65000.00:
ID -------- ----------
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
#OR
operator is also used to combine multiple conditions in the WHERE clause of an SQL statement. When using the OR operator, as long as any one of the conditions is true, the entire condition is true. For example, [condition1] OR [condition2] is true whenever either condition1 or condition2 is true.Grammar
The basic syntax of the OR operator with a WHERE clause is as follows:SELECT column1, column2, columnN
FROM table_nameYou can use the OR operator to combine N quantities of conditions. The action that a SQLite statement needs to perform is, whether it is a transaction or a query, as long as any condition separated by OR is true (TRUE).
Example
Suppose the COMPANY table has the following records:
1 " Paul " 32 " California 20000.0
2 " Allen 25 Texas 15000.0
3 Teddy 23 NORWAY 20000.0 ## 4 Mark 25 Rich-Mond 65000.0
5 David 27 TEXAS 85000.0
6 KIM 22 South-Hall 45000.0
7 Jamest On 10000.0
The following SELECT statement lists all records with AGE greater than or equal to 25 or salary greater than or equal to 65000.00:
ID ----------------------------------------------—
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0 ## 4 MARK 25 Rich-Mond 65000.0 ## 5 David 27 Texas 85000.0