menu

SQL – AND & OR

SQL – AND & OR Clauses

SQL – AND & OR Explained

AND Clause :

And Clause displays the results where both the conditions are fullfilled.

OR Clause :

OR Clause displays the results where atleast one conditions is fullfilled.

Suppose we have following data :

tableFull

AND Clause Example :

Example

SELECT * FROM Users WHERE (City=”DELHI” and Name=’Riya’);

Where [City=”DELHI” and Name=’Riya’] Both Conditions are satisfied.

This Will Produce The Result As :

SQL - AND & OR

OR Clause Example :

Example

SELECT * FROM Users WHERE (City=”DELHI” OR Name=’Riya’);

Where [City=”DELHI” OR Name=’Riya’] Either condition is satisfied.

This Will Produce The Result As :

SQL - AND & OR

AND & OR Clause Together Example :

This will select the result where city is (“delhi” or name is “riya” )[produces two rows]
with the condition followed by name “linga” [Selects one from the two rows where name is “linga”]

Example

SELECT * FROM Users WHERE (City=”DELHI” OR Name=’Riya’) AND Name=’linga’;

This Will Produce The Result As :

SQL - AND & OR

Advertisements