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


Popular posts from this blog

Rules for Constructing Character Constants

My Bisalpur- Population

How to bind dropdownlist inside gridview edit template