SQL: Using AND and OR

 

AND
Introduction

 

  • AND means that two expressions by AND must evaluate to TRUE

Example:

Who are all the people in my contact list that have the first name Jon and have a birthday later than 1965?
SELECT p.person_first_name FROM person p

WHERE p.person_first_name = ‘Jon’ AND

p.birthday > 12/31/1965;

 

 

OR
Introduction

 

  • OR means that if either of the two combined expressions evaluates to TRUE, the row becomes part of the result set

Example:

Who are all the people in my contact list that have the first name Jon or a last name of Flanders?
SELECT p.person_first_name FROM person p

WHERE p.person_first_name = ‘Jon’ OR

p.person_last_name = ‘Flanders’;

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s