Back-End Development SQL basics

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.id C.name C.contact C.address
123eed3 Tarun 987654321 mohali
aa22103 Tarun 987650000 chd
00146hh Sia 812300912 panchukula
144dcv4 Rahul 700912366 chd

AND operator example

Result:

C.id C.name C.contact C.address
aa22103 Tarun 987650000 chd

OR operator example

Result:

C.id C.name C.contact C.address
123eed3 Tarun 987654321 mohali
aa22103 Tarun 987650000 chd
144dcv4 Rahul 700912366 chd

Using both SQL AND & OR Operators

Result

C.id C.name C.contact C.address
123eed3 Tarun 987654321 mohali
aa22103 Tarun 987650000 chd