The SQL AND & OR operators support compound conditions in the SQL WHERE clause.
Use SQL AND & OR operators in case when a WHERE clause requires multiple conditions. For example, we may want to select a list of CUSTOMERS whose accounts are on credit hold and whole credit balance exceeds the credit limit. Such a statement may look like this:
SQL AND & OR are placed between conditions to create compound conditions. Parenthesis can be used to group conditions.
SQL AND & OR Syntax
SQL AND & OR Example
The following example selects a list of rows from the branch table that have an employee_count less than 4 or greater than 6.
Here are the contents of the table:
Table: BRANCH
| branch_nbr | branch_name | region_nbr | employee_count |
| 108 | New York | 100 | 10 |
| 110 | Boston | 100 | 6 |
| 212 | Chicago | 200 | 5 |
| 404 | San Diego | 400 | 6 |
| 415 | San Jose | 400 | 3 |
This SQL Statement with AND & OR is executed:
Here is the result.
| branch_nbr | branch_name | employee_count |
| 108 | New York | 10 |
| 415 | San Jose | 3 |
Advertisements:
Infogoal.com is organized to help you gain mastery.
Examples may be simplified to facilitate learning.
Content is reviewed for errors but is not warranted to be 100% correct.
In order to use this site, you must read and agree to the
terms of use, privacy policy and cookie policy.
Copyright 2006-2020 by Infogoal, LLC. All Rights Reserved.