Sqlite And Or Clauses
# SQLite AND/OR Operators
SQLite's **AND** and **OR** operators are used to compile multiple conditions to narrow down the data selected in an SQLite statement. These two operators are called conjunction operators.
These operators allow multiple comparisons between different operators within the same SQLite statement.
## AND Operator
The **AND** operator allows the existence of multiple conditions in a WHERE clause of an SQL statement. When using the AND operator, the entire condition is true (true) only when all conditions are true (true). For example, AND is true (true) only when both condition1 and condition2 are true (true).
## Syntax
The basic syntax of the AND operator with a WHERE clause is as follows:
SELECT column1, column2, columnN FROM table_name WHERE AND ...AND ;
You can use the AND operator to combine N number of conditions. The action required by the SQLite statement, whether it's a transaction or a query, is that all conditions separated by AND must be TRUE.
## Example
Assume the COMPANY table has the following records:
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
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 James 24 Houston 10000.0
The following SELECT statement lists all records where AGE is greater than or equal to 25 **AND** the salary is greater than or equal to 65000.00:
sqlite> SELECT * FROM COMPANY WHERE AGE >= 25 AND SALARY >= 65000;
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
## OR Operator
The **OR** operator is also used to combine multiple conditions in a WHERE clause of an SQL statement. When using the OR operator, the entire condition is true (true) as long as any one of the conditions is true (true). For example, OR is true (true) as long as either condition1 or condition2 is true (true).
## Syntax
The basic syntax of the OR operator with a WHERE clause is as follows:
SELECT column1, column2, columnN FROM table_name WHERE OR ...OR
You can use the OR operator to combine N number of conditions. The action required by the SQLite statement, whether it's a transaction or a query, is that any one of the conditions separated by OR must be TRUE.
## Example
Assume the COMPANY table has the following records:
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
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 James 24 Houston 10000.0
The following SELECT statement lists all records where AGE is greater than or equal to 25 **OR** the salary is greater than or equal to 65000.00:
sqlite> SELECT * FROM COMPANY WHERE AGE >= 25 OR SALARY >= 65000;
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
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
[](#)(#)
(#)[](#)
YouTip