English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
SQLite AND
&OR
operators are used to compile multiple conditions to narrow down the range of selected data in SQLite statements. These two operators are called conjunctive operators.
These operators provide a way to make multiple comparisons with different operators in the same SQLite statement.
AND
operators allow multiple conditions to exist in the WHERE clause of SQLite statements. When using the AND operator, it is assumed that the complete condition is true when all conditions are true. For example, only when condition1and condition2are all true, then [condition1] AND [condition2] will be true.
The basic syntax of the AND operator with the WHERE clause is as follows.
SELECT column1, column2, columnN FROM table_nameWHERE [condition1] AND [condition2]...AND [conditionN];
You can combine N conditions using the AND operator. For operations to be performed by the SQLite statement (whether it is a transaction or a query), all conditions separated by AND must be TRUE.
Please see the COMPANY table with 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 the records with AGE greater than or equal to25 AND
salary (SALARY) is greater than or equal to65000.00 records.
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
The OR operator is also used to combine multiple conditions in the WHERE clause of SQLite statements. When using the OR operator, if at least one condition is true, it is assumed that the complete condition is true. For example, if condition1or condition2is true, then [condition1] or [condition2] will be true.
The basic syntax of the OR operator with the WHERE clause is as follows.
SELECT column1, column2, columnN FROM table_nameWHERE [condition1] OR [condition2]...OR [conditionN]
You can combine N conditions using the OR operator. For operations to be performed by the SQLite statement, whether it is a transaction or a query, only one of the conditions separated by OR must be TRUE.
Please see the COMPANY table with 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 the records with AGE greater than or equal to25 OR
Salary greater than or equal to65000.00 records.
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