SQL Server Tutorial
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 is used to retrieve data with a specific condition.
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.
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>1Output:
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=2Output:
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<=4Output:
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=4Output:
(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
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=4Output:
(1 row(s) affected)
SQL Server Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page