codescracker


sql

SQL And & Or Operator



« Previous Tutorial Next Tutorial »


SQL AND & OR operators are basically used to filter the records based on multiple conditions.

SQL AND Operator

The SQL AND operator is used to display a record only if both the first condition AND the second condition becomes true. Here is the general form of the AND operator with SQL WHERE Clause:

SELECT col1, col2, colN 
FROM table_name
WHERE [condition1] AND [condition2]...AND [conditionN];

SQL AND Operator Example

Here is an example of SQL AND operator. Let's consider the following table CUSTOMERS having the records:

SQL and or

Following is an example, which will fetch the following columns:

from the table CUSTOMERS where salary is greater than 78000.00 AND age is less than 32 years

SELECT ID, NAME, SALARY 
FROM CUSTOMERS
WHERE SALARY > 78000.00 AND age < 32;

After querying the above SQL statements, you will get the following output:

SQL AND

SQL OR Operator

The SQL OR operator is used to display a record only if either the first condition OR the second condition becomes true. Here is the general form of the OR operator with the WHERE clause in SQL:

SELECT col1, col2, colN 
FROM table_name
WHERE [condition1] OR [condition2]...OR [conditionN]

SQL OR Operator Example

Here is an example of SQL OR operator. Let's consider the table named CUSTOMERS having the following records:

SQL OR

Following is an example, which will fetch the following columns:

from the table CUSTOMERS where salary is greater than 86000.00 OR age is less than 30 years

SELECT ID, NAME, SALARY 
FROM CUSTOMERS
WHERE SALARY > 86000.00 OR age < 30;

After querying the above SQL statements, you will get the following output:

SQL and or operator

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test