Latest web development tutorials

SQLite AND / OR operator

SQLiteAND and ORoperators are used to compile multiple criteria to narrow down the selected data in SQLite statement. These two operators are called concatenation operator.

These operators SQLite statement for the same number of different comparisons between operators possible.

AND operator

AND operator allows multiple conditions exist in a SQL statement in the WHERE clause.When using the AND operator, only when all the conditions are true (true), the entire condition is true (true). For example, only when condition1 and condition2 are true (true) when, [condition1] AND [condition2] is true (true).

grammar

The basic syntax of the WHERE clause with the AND operator as follows:

SELECT column1, column2, columnN 
FROM table_name
WHERE [condition1] AND [condition2] ... AND [conditionN];

You can use the AND operator to combine the N number of conditions. Action SQLite statements requires that either the transaction or query, all separated by AND conditions must be true (TRUE).

Examples

Suppose 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 AGE 25and greater than or equal greater than or equal wages for all records 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

OR operator is also used in conjunction with one SQL statement multiple conditions in the WHERE clause.When using OR operator only when any one condition is true (true), the entire condition is true (true). For example, whenever condition1 or condition2 have real (true) when a is, [condition1] OR [condition2] is true (true).

grammar

The basic syntax of the WHERE clause with the OR operator as follows:

SELECT column1, column2, columnN 
FROM table_name
WHERE [condition1] OR [condition2] ... OR [conditionN]

You can use the OR operator to combine the N number of conditions. Action SQLite statements requires that either the transaction or query, as long as any one separated by the OR condition is true (TRUE) can be.

Examples

Suppose 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 AGE 25or greater than or equal greater than or equal wages for all records 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