AND Operator in SQL Server with Example or Use SQL AND Operator in Where Clause

  Total Views : 401
  Comments : 0
 
  Keywords : SQL and operator example, Sql and operator in where clause example, How to use AND operator in sql server with example, Why we need AND operator in sql server

Here we will learn what is AND operator in sql server and how to use AND operator in sql server with examples.

SQL AND Operator

The AND operator in SQL is used to compare data with more than one condition. If all the conditions returns TRUE then only it will display records. Generally we will use this operator in WHERE clause and syntax for AND operator in SQL will be like as shown below

Syntax for SQL AND Operator

Following sql statement is the syntax of AND operator in sql 

 

SELECT column1, column2 FROM tablename WHERE column1 ='somevalue' AND column2='Somevalue'

We will check this with example for that first create “EmployeeDetails” table by using following script in sql database

 

create table EmployeeDetails(empid int, empname varchar(50),designation varchar(50),salary int,Location varchar(50))

 

insert into EmployeeDetails

values(1,'suresh','software engineer',25000,'chennai'),

(2,'rohini','AEO',15000,'chennai'),

(3,'madhavsai','business analyst',50000,'nagpur'),

(4,'mahendra','CA',75000,'guntur'),

(5,'sateesh','Doctor',65000,'guntur')

 

select * from EmployeeDetails

Once we run above sql script our table “EmployeeDetails” will create and result will be like as shown below

 

Newly created employeedetails table in sql server

 

Now run following examples to check AND operator in SQL

SQL AND Operator Example1

In following SQL query we are checking multiple conditions (Location, Salary) with AND operator. It will return records whatever it satisfy both the conditions.

 

SELECT * FROM EmployeeDetails WHERE Location='guntur' AND Salary>40000

Once we run above sql query our result will be like as shown below

 

Output

 

Following is the output of sql server and operator example

 

SQL AND Operator Example Output

SQL Server AND Operator Example2

In following SQL query we are checking Location and Empname conditions with AND operator. It will return records whatever it satisfy both the conditions.

 

SELECT * FROM EmployeeDetails WHERE Location='chennai' AND Empname='suresh'

When we run above sql query our output for sql and operator will be like as shown below 

 

Output

 

Following is the output of sql server and operator example

 

SQL Server AND Operator Example with Output

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User