Where clause is very important clause for filtering data .It search the records from the table according to the condition given in the where clause.

We can use following operator in the where clause

1-    =

2-   

3-   

4-    <=

5-    >=

6-    Between

7-    Like

8-    In

Suppose a table name Emp_Info and have following records

Where Clause in SQL Statement

Now we take example of each operator on by one

select Emp_Name,Salary from Test.dbo.Emp_Info where salary=1000

 

output

Where Clause in SQL Statement

select Emp_Name,Salary from Test.dbo.Emp_Info where salary < 1500

 

Output


Where Clause in SQL Statement

select Emp_Name,Salary from Test.dbo.Emp_Info where salary > 1500

 

output


Where Clause in SQL Statement

select Emp_Name,Salary from Test.dbo.Emp_Info where salary <= 1300

 Where Clause in SQL Statement


select Emp_Name,Salary from Test.dbo.Emp_Info where salary >= 1600


Where Clause in SQL Statement

select Emp_Name,Salary from Test.dbo.Emp_Info where salary between 1000 and 1300

 Where Clause in SQL Statement


Like Condition


Like condition is use for pattern matching and return result according to


the pattern.

 

1-   % wildcard –it matches string of any length


2-   _ wildcard- it matches single character


3-   [] wildcard-it matches any character from the []


4-   [^] wildcard-it not matches the character that is in[^]

 

Suppost we have Employee table and have following records


Where Clause in SQL Statement

select * from Test.dbo.Employee where Name   Like '%h';


Where Clause in SQL Statement

In-It return all the records between two condition .it allows multiple values in where clause.

select * from Test.dbo.Emp_Info where salary IN (1000,1200)     


Where Clause in SQL Statement

You can also visit these related articles & blogs

SQLite Where clause

What is the difference between a HAVING CLAUSE and a WHERE CLAUSE

  Modified On Mar-17-2018 01:21:48 AM

Leave Comment