SQL Server Where Statement

SQL Server WHERE Statement

WHERE Statement is used to filter the rows with the specific condition.

While querying a database, we can view only those rows that meet a specific condition.

WHERE statement can be used with SELECT, UPDATE and DELETE statements and cannot be used alone to query the database.

SELECT And WHERE Statement

SELECT and WHERE statement is used to retrieve data with a specific condition.

SELECT And WHERE Syntax

SELECT column_name1, column_name2, ....
FROM table_name
WHERE filter_codition

column_name is the name of the column in the database table to retrieve.

table_name is the name of the table in database.

filter_condition is used to filter the rows in the table.

SELECT And WHERE Statement Example

Selection rows with specific columns in database table 'Employee' using filter condition as Id column value must be greater than 1.

SELECT Id, Name, DeptId, Email
FROM Employee
WHERE Id>1
Output:
Select with where statement output

Selection rows with specific columns in database table 'Employee' using filter condition as Id column value must be equal to 2.

SELECT Id, Name, DeptId, Email
FROM Employee
WHERE Id=2
Output:
Select with where statement output

Selection rows with specific columns in database table 'Department' using filter condition as Id column value must be less than or equal to 4.

SELECT Id, Name
FROM Department
WHERE Id<=4
Output:
Select with where statement output

UPDATE And WHERE Statement

UPDATE Statement is used to update specific column values in table rows.

UPDATE with WHERE Statement is used to update specific column values in specific rows in the table based on filter condition.

UPDATE Department SET Name = 'New Department4'
WHERE Id=4
Output:
  (1 row(s) affected)

We can also check whether column value is updated or not using SELECT Statement as below.

SELECT Id, Name
FROM Department
WHERE Id=4
Select with where statement output

DELETE And WHERE Statement

DELETE Statement is used to remove the table rows.

DELETE with WHERE Statement is used to remove specific rows in the table based on filter condition.

DELETE
FROM Department
WHERE Id=4
Output:
  (1 row(s) affected)



Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^