Top Menu

Search This Blog

SQL AND & OR Operators

The AND & OR operators are used to filter records to find more than one condition.

AND Operator syntax:


 SELECT * FROM table_name
WHERE Column_1_name operator value
AND Column_2_name operator value

OR Operator syntax:


 SELECT * FROM table_name
WHERE Column_1_name operator value
OR Column_2_name operator value

AND & OR both Operator syntax:


 SELECT * FROM table_name
WHERE Column_1_name operator value
AND (Column_2_name operator value OR Column_2_name operator value)

As you see, we have like this "Candidate" table.











Example:

AND Operator:

SELECT * FROM CANDIDATE
WHERE Address='amreli'
AND LastName='patel'

Output:

                                                                                                                                                                   
OR Operator:


SELECT * FROM CANDIDATE
WHERE Address='amreli'
OR LastName='patel'

Output:

                                                                                                                                                               
AND & OR both Operator:


SELECT * FROM CANDIDATE
WHERE Address='ahmedabad'
AND (LastName='patel' OR FirstName='vishal')

Output:


Post a Comment

Designed by OddThemes | Distributed By Gooyaabi Templates