Use this space to put some text. Update this text in HTML

468x60 banner ad

Advertise with Us

Powered by Blogger.

Saturday, 19 March 2016

Sql Where Clause



The WHERE Clause is used to find out exact record from the table on the basis of specific criteria or condition.

For example:
when you want to see the information about EMPLOYEE whose department is banking. Retrieving information about the specific department would less processing time for the query. Retrieving information about the entire department would increase the processing time for the query.


SQL WHERE clause, which we can use to restrict the data that is retrieved. The condition you provide in the WHERE clause filters, the rows retrieved from the table and gives you only those rows which you want to see. The WHERE clause is not only used in SELECT statement, but it is also used in UPDATE, DELETE statement.


SQL WHERE Syntax:
 
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;

You can specify a condition using comparison and logical operators like >, <, =, LIKE, NOT, etc. Below examples demonstrate you clearly.

CREATE TABLE [dbo].[Employee]

(

  [Employee_id] [int] IDENTITY(1,1) NOT NULL,
  [First_name] [nvarchar](300) NULL,
  [Last_name] [nvarchar](300) NULL,
  [Salary] [decimal](20, 2) NULL,
  [Joining_date] [datetime] NULL,
  [Department] [nvarchar](200) NULL
) ON [PRIMARY]

INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('John', 'Abraham', 1000000.00, 1905-06-07, 'Banking')
INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('Michael', 'Clarke', 800000.00, 1894-06-28, 'Insurance')

INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('Roy', 'Thomas', 700000.00, 1894-06-27, 'Banking')
INSERT [dbo].[Employee] ([First_name], [Last_name], [Salary], [Joining_date], [Department]) VALUES ('Tom', 'Jose', 600000.00, 1894-06-27, 'Insurance')

 Example1:

SELECT First_name,Last_name, Salary,Department
FROM Employee
WHERE Department='Banking'

In this SQL WHERE clause example, we have used the SQL WHERE clause to filter our results from the EMPLOYEE table. The SQL statement above would return First_name,Last_name, Salary, Department from the EMPLOYEE table where the Department is banking


  
Example2:


SELECT First_name,Last_name, Salary,Department

FROM Employee
WHERE Department='Insurance'

In this SQL WHERE clause example, we have used the SQL WHERE clause to filter our results from the EMPLOYEE table. The SQL statement above would return First_name,Last_name, Salary, Department from the EMPLOYEE table where the Department is Insurance.
 


 Example3:


SELECT First_name,Last_name, Salary,Department

FROM Employee
WHERE Salary=600000

In this SQL WHERE clause example, we have used the SQL WHERE clause to filter our results from the EMPLOYEE table. The SQL statement above would return First_name,Last_name, Salary, Department from the EMPLOYEE table where the Salary is 600000.
 



 Example4:


SELECT First_name,Last_name, Salary,Department
FROM Employee
WHERE Salary > 600000

In this SQL WHERE clause example, we have used the SQL WHERE clause to filter our results from the EMPLOYEE table. The SQL statement above would return First_name,Last_name, Salary, Department from the EMPLOYEE table where the Salary greater than 600000.

 








No comments :

Post a Comment

Ask a Question?