AND and OR Operator in Sql Server

And & Or:- These Operators are used to further filter the recordset return by SQL queries when more than one conditions are specified. In case of “AND” all the conditions must be true and in case of “OR” any of the condition must be true.
In this article, we are going to use the table Employee for explaining examples. Structure of this table is given below:-
CREATE TABLE [dbo]. [Employee](
[Empid] [Int] IDENTITY (1, 1) NOT NULL Primary key,
[EmpNumber] [nvarchar](50) NOT NULL,
[EmpFirstName] [nvarchar](150) NOT NULL,
[EmpLAStName] [nvarchar](150) NULL,
[EmpEmail] [nvarchar](150) NULL,
[Salary] [int] NULL

Following Insert queries will insert data into the table Employee

Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,salary)
Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,salary)
Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,salary)
Insert Into Employee (EmpNumber,EmpFirstName,EmpLAStName,EmpEmail,salary)

For example, in case of “AND”, suppose we want to get records from the table Employee whose last name is “Sharma” and salary less than 300000, then we can use the following query:-

Select * from employee where EmpLastName=’Sharma’ AND salary < 300000

This query will return the record of the employee whose empnumber is “A004”.

In case of “OR”, suppose we want to get records from the table Employee whose last name is either Sharma or salary is less than 300000, then we can use the following query

Select EmpNumber from employee where EmpLastName=’Sharma’ OR salary  <  300000

This query will returns all the records:-


About vivekjohari

Database Consultant with more than 11.5 years of experience in database designing & programming and DBA related activities.  Had good experience on different databases like SQL Server, MySQL & Oracle, Azure SQL &  Big Data.
This entry was posted in SQL Basic Concepts, SQL Server and tagged . Bookmark the permalink.

31 Responses to AND and OR Operator in Sql Server

  1. Pingback: Mitchell Brownlie

  2. Pingback: sports

  3. Pingback: meja qq

  4. Pingback: visit

  5. Pingback: cornhole board game

  6. Pingback: ww88

  7. Pingback:

  8. Pingback:

  9. Pingback: w88 vn com

  10. Pingback: 카지노사이트

  11. Pingback: El día que mataron a Monseñor Romero

  12. Pingback: Samsara Market

  13. Pingback: Dream Market

  14. Pingback: ปล่อยเงินด่วน

  15. Pingback: Cryptonia Market Exit Scam

  16. Pingback: Middle East and Africa Marketing Automation Software Market, Size, Trends and Future Scope by P&S Intelligence

  17. Pingback: ดูบอลสด

  18. Pingback: Digital Income System

  19. Pingback: ca cuoc lmht truc tuyen

  20. Pingback: ca cuoc the thao online

  21. Pingback: cuoc xien online

  22. Pingback: Sea Games 2019

  23. Pingback:

  24. Pingback: saranapoker1

  25. Pingback: ignou mapc

  26. Pingback:

  27. Pingback: 2015louisvuittonoutlet

  28. Pingback: CBD OIL

  29. Pingback:

  30. Pingback: datasgp

  31. Pingback: اخبار

Leave a Reply