Tag Archives: OR operator

AND & OR Operator in SQL Query

AND & OR Operator in SQL Query

AND Operator is used in which you must have to satisfy the both or all condition for executing the next steps or getting result from SQL Query. It will not work if any one condition is false. In AND it must satisfy all condition to run.

OR Operator is used in which you must satisfy any one condition or both condition then it will go to next steps or getting result from SQL Query. It will not work if all condition is false. In OR it must satisfy any one condition to run.

Syntax for AND:

Select * from table_name where columnname = 'value' and columnname2 = 'value2';

Syntax for OR:

Select * from table_name where columnname = 'value' or columnname2 = 'value2';

Example for AND operator:
Example will return the value of employee name from employees table if it satisfy both condition on where clause .

Select employee_name from employees where salary > 10000 and department_no = 10;

Example for OR Operator:
Example will return the value of employee name if any one condition is correct.

Select employee_name from employees where salary > 10000 or Department_no = 10;