SQL And And Or Clause

Tips >>SQL

AND & OR

MAKE FULL WEB APPLICATION WITH JUST SQL KNOWLEDGE? CLICK HERE

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
= "Shah"

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@virtualsplat.com
Phone : +91-9892413501

Whatsapp Icon +91-9967648641

Whatsapp Icon +91-9967648641