SQL Operators
These Operators are used to filter record based on more than one condition.
SQL AND & OR Operators
AND operator displays record if the both condition are true.
OR operator displays record if either the one condition is true.
Below is selection from "Student" table:
StudentID | Student Name | Address | Country |
---|---|---|---|
1 | Ajay | Noida | India |
2 | Ajeet | Bareilly | India |
3 | Shivam | Nagaland | India |
4 | Monu | Noida | India |
Example:
AND:
SELECT * FROM Student
WHERE Address='Noida'
AND Country='India';
Result:
StudentID | Student Name | Address | Country |
---|---|---|---|
1 | Ajay | Noida | India |
4 | Monu | Noida | India |
OR:
SELECT * FROM Student
WHERE Address='Noida'
OR Country='India';
Result:
StudentID | Student Name | Address | Country |
---|---|---|---|
1 | Ajay | Noida | India |
2 | Ajeet | Bareilly | India |
3 | Shivam | Nagaland | India |
4 | Monu | Noida | India |
Combine AND & OR Condition:
SELECT * FROM Student
WHERE Country='India'
AND (Address='Noida' OR Address='Bareilly');
Result:
StudentID | Student Name | Address | Country |
---|---|---|---|
1 | Ajay | Noida | India |
2 | Ajeet | Bareilly | India |
4 | Monu | Noida | India |
2 comments
Click here for commentsI think there is wrong in OR and Combined AND & OR Condition.
ReplyYa due to typing mistake this is happened.... Sorry for this
ReplyConversion Conversion Emoticon Emoticon