Latest Post

Thursday, 31 August 2017

Where Clause in sql server

Where Clause
WHERE can be used clause with SELECT, INSERT, UPDATE and DELETE statement to filtering rows and it applies on each and every row.
  • WHERE clause is used before GROUP BY clause.
  • We can't use aggregate functions in the where clause 
Following is employee Table where I will demonstrate the where clause.
EMPNO
ENAME
JOB
SAL
DEPT
DEPTNO
DNAME
LOC
NULL
NULL
NULL
NULL
NULL
1
ACCOUNTING
ST LOUIS
NULL
NULL
NULL
NULL
NULL
2
RESEARCH
NEW YORK
2
Anil
Manager
12000
3
3
SALES
ATLANTA
3
Adam
Developer
6700
3
3
SALES
ATLANTA
5
Tina
Developer
3000
3
3
SALES
ATLANTA
1
Alok
Admin
18000
4
4
OPERATIONS
SEATTLE
4
Anit
Developer
4500
4
4
OPERATIONS
SEATTLE

Fetching all employee that belongs to DEP 3
SELECT * FROM  EMP WHERE EMP.DEPT=3

OutPut:-
EMPNO
ENAME
JOB
SAL
DEPT
DEPTNO
DNAME
LOC
2
Anil
Manager
12000
3
3
SALES
ATLANTA
3
Adam
Developer
6700
3
3
SALES
ATLANTA
5
Tina
Developer
3000
3
3
SALES
ATLANTA

Retrieving employees whose salary is above 10000

SELECT * FROM  EMP WHERE EMP.DEPT=3 and Emp.SAL>10000

OutPut:-
EMPNO
ENAME
JOB
SAL
DEPT
DEPTNO
DNAME
LOC
2
Anil
Manager
12000
3
3
SALES
ATLANTA


I am hoping that you are enjoying with this post! Please share with you friends. Thank you!!

Government Jobs