SQL AND & OR Operators

SQL AND & OR Operators

Hi friends, in this post we will learn about SQL AND & OR OperatorsAND & OR Operators is used to filter data from table based on one or more conditions.

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.

Earlier we had discussed about SQL Where ClauseDelete Query SQL ServerSQL Update StatementSQL Select StatementSQL Insert StatementDrop Table SQL ServerRename Table in SQL ServerCreate Table SQL ServerSchema In SQL ServerSQL Server OperatorsData Type in SQL Server and Drop-Delete SQL Server Database Using Management Studio or Query.

Table Structure:

ID NAME CLASS PERMADDRESS TEMPADDRESS
1 MANN XI AGRA NULL
2 JAI X MUMBAI NULL
3 AKSHAY IX GOA NULL
4 OM V DELHI NULL
5 AMAN VII GOA NULL
6 AMIT VII JAIPUR NULL

SQL AND & OR Operators Query Syntax:

----SELECT DATABASE----
USE HIGHTECHNOLOGY
GO
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
----AND CLAUSE----
SELECT * FROM STUDENT_INFORMATION WHERE ID=1 AND NAME='MANN'
GO

----OR CLAUSE----
SELECT * FROM STUDENT_INFORMATION WHERE ID=1 OR ID=2
GO

----AND & OR CLAUSE----
SELECT * FROM STUDENT_INFORMATION WHERE ID=2 AND NAME='OM' OR NAME='JAI'
GO

In above query we are using STUDENT_INFORMATION table for demo purpose.

AND Operator: Select all student information where id=1 and name=mann in the table.

OR Operator: Select all student information where id=1 or id=2 in table.

AND & OR Operator: Select all student information where id =3 and id=4 or name=jai in table.

SQL AND & OR Operators