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 :
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 :
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 :
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 :
Advertisements
Add Comment
📖 Read More
- 1. SQL ORDER BY
- 2. SQL - UPDATE
- 3. SQL - DELETE
- 4. SQL - Like
- 5. SQL In Operator
- 6. SQL Between
- 7. SQL Joins - INNER JOIN
- 8. SQL - LEFT JOIN
- 9. SQL - RIGHT JOIN
- 10. SQL - FULL JOIN