| |
SQL And And Or Clause
|
| Tips >>SQL
|
|
AND & OR
|
|
AND and OR join two or more conditions in a WHERE clause.
The AND operator displays a row if ALL conditions listed are
true. The OR operator displays a row if ANY of the conditions listed
are true.
Original Table (used in the examples)
| LAST NAME |
FIRST NAME |
ADDRESS |
CITY |
| Malhotra |
Anjali |
Highland |
Mumbai |
| Shah |
Tina |
Gaurang |
Mumbai |
| Shah |
Krishna |
Kalpatru |
Mumbai |
EXAMPLE I :-
Use AND display each person with the first name equal to "Tina",
and the last name equal to "Shah":
|
SELECT * FROM Persons WHERE
First Name='Tina'AND Last Name='Shah
|
RESULT:-
| LAST NAME |
FIRST NAME |
ADDRESS |
CITY |
| Shah |
Tina |
Gaurang |
Mumbai |
EXAMPLE II :-
Use OR is to display each person with the first name equal to
"Tina", or the last name equal to "Shah":
|
SELECT * FROM Persons WHERE
first name='Tina'OR last name='Shah'
|
RESULT:-
| LAST NAME |
FIRST NAME |
ADDRESS |
CITY |
| Shah |
Tina |
Gaurang |
Mumbai |
| Shah |
Krishna |
Kalpatru |
Mumbai |
EXAMPLE III :-
You can also combine AND and OR (use parentheses to form complex
expressions):
|
SELECT * FROM Persons WHERE
(FirstName='Tina' OR FirstName='Krishna')AND LastName='Shah'
|
RESULTS:-
| LAST NAME |
FIRST NAME |
ADDRESS |
CITY |
| Shah |
Tina |
Gaurang |
Mumbai |
| Shah |
Krishna |
Kalpatru |
Mumbai |
If you don't find what you are looking for. Please click
here to submit your query, our experts will reply soon.
|
| |
| |
E-mail : sales at virtualsplat dot com
Phone : +91 022 28067978