In the previous section of SQL Tutorial, we have seen that the SQL WHERE
keyword can be used to conditionally select data from a
table in database. This condition can be a simple condition like the
one presented in the previous section of this SQL Tutorial, or it can be a compound
condition. Compound conditions are made up of multiple simple SQL
conditions connected by SQL AND or OR Keywords. There is no limit to the number
of simple conditions that can be present in a single SQL statement.
The syntax for a compound condition of SQL AND OR Keywords are as follows:
The {}+ means that the expression inside the bracket will
occur one or more times. Note that SQL AND and OR keywords can be used
interchangeably. In addition, we may use the parenthesis sign
() to indicate the order of the condition.
For example, we may wish to select all Employess record who have Salary
greater than 1000$ or all Employees who have Salary less then equals 1200$ in table Employees_Salary,
Table of
Employees_Salary
| FirstName |
Month |
Salary |
| Austin |
January |
1100$ |
| Creston |
January |
1000$ |
| Kate |
January |
1200$ |
| Angela |
January |
1000$ |
| Bobbi |
January |
1250$ |
| Cute |
January |
1300$ |
Result or SQL AND OR Keywords Example
| FirstName |
Month |
Salary |
| Austin |
January |
1100$ |
| Kate |
January |
1200$ |
Explanation of above query
Here we can see that only the Austin and Kate are the only two
employees who are having Salary more then 1000$ and less then equals 1200$.
Other records are not meeting the criteria of our requirements.