SQL Basic- SQL Operators(AND & OR)


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 comments
5 November 2015 at 21:36 ×

I think there is wrong in OR and Combined AND & OR Condition.

Reply
avatar
5 November 2015 at 21:40 ×

Ya due to typing mistake this is happened.... Sorry for this

Reply
avatar