SQL AND & OR Operators

      No Comments on SQL AND & OR Operators

The SQL AND & OR operators are used to filter records based on more than one condition.

  • The AND Operator fetches a record if both the conditions specified evaluate to true.
  • The OR Operator fetches a record if any of the specified condition evaluate to true.

Consider a demo database

C.idC.nameC.contactC.address
123eed3Tarun987654321mohali
aa22103Tarun987650000chd
00146hhSia812300912panchukula
144dcv4Rahul700912366chd

AND operator example

SELECT * FROM Customers
WHERE C.name='Tarun'
AND C.address='chd'; 

Result:

C.idC.nameC.contactC.address
aa22103Tarun987650000chd

OR operator example

Select * from Customers WHERE C.address='chd' OR C.address='mohali';

Result:

C.idC.nameC.contactC.address
123eed3Tarun987654321mohali
aa22103Tarun987650000chd
144dcv4Rahul700912366chd

Using both SQL AND & OR Operators

Select * from customers WHERE C.name='Tarun' AND( C.address='chd= OR C.address='mohali');

Result

C.idC.nameC.contactC.address
123eed3Tarun987654321mohali
aa22103Tarun987650000chd

Leave a Reply

Your email address will not be published. Required fields are marked *