Where Clause in SQL
Table of Content:
Code: SQL Server Syntax
SELECT column1, column2, ...columnN FROM table_name WHERE condition;
Example:
If you don't have table please create below table and practice it.
-- My database name is SQLExamples USE SQLExamples -- Create this below Employee table DROP TABLE Employee CREATE TABLE Employee( EmpId INT, EmpName VARCHAR(25), EmpAddress VARCHAR(100), EmpDept VARCHAR(25) ) -- Insert data inside table INSERT INTO Employee VALUES (1, 'Rambo', 'Kolkata', 'IT'), (2, 'Rohit', 'Kolkata', 'IT'), (3, 'Rohon', 'Kolkata', 'ITIS'), (4, 'Ronok', 'Kolkata', 'ITIS'), (5, 'Rubin', 'Kolkata', 'ITIS'), (6, 'Sorif', 'Kolkata', 'ADMIN'), (7, 'Soriful', 'Kolkata', 'ADMIN'), (8, 'Sofik', 'Kolkata', 'ADMIN')
SELECT * FROM Employee
Output:
The above code will produce the following result-
EmpId |
EmpName |
EmpAddress |
EmpDept |
1 |
Rambo |
Kolkata |
IT |
2 |
Rohit |
Kolkata |
IT |
3 |
Rohon |
Kolkata |
ITIS |
4 |
Ronok |
Kolkata |
ITIS |
5 |
Rubin |
Kolkata |
ITIS |
6 |
Sorif |
Kolkata |
ADMIN |
7 |
Soriful |
Kolkata |
ADMIN |
8 |
Sofik |
Kolkata |
ADMIN |
Code:
SELECT EmpId, EmpName FROM Employee WHERE EmpDept = 'IT'
Output:
The above code will produce the following result-
EmpId |
EmpName |
1 |
Rambo |
2 |
Rohit |