SQL AND & OR Operators

SQL AND & OR Operators are operators are used in conditions like WHERE clause, if it’s more than one condition. Basically we can use these AND & OR Operators in WHERE Clause of an SQL statement.

The AND operator displays a record if both the first condition AND the second condition are true.
The OR operator displays a record if either the first condition OR the second condition is true.

Simple Example of SQL AND & OR Operators usage in SQL statements :

AND Operator example

SELECT * FROM table_name WHERE column1 = value1 AND column2 = value2;

OR Operator example

SELECT * FROM table_name WHERE column1 = value1 OR column2 = value2;

Combining SQL AND & OR Operators for more complex SQL Statements

If you want to filter results with AND operator between two columns & OR operator between other, then you can use this below SQL statement.

SELECT * FROM table_name WHERE (column1 = value1 AND column2 = value2) OR column3 = value3;

There is one more condition, if you wan to use OR operator between two columns & And Operator between other column, then you can use this below statement.

SELECT * FROM table_name WHERE column1 = value1 AND (column2 = value2 OR column3 = value3);

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe