SQL Query To Get EmpIDs Department Wise

This is tricky but most common question in Interviews. Popular question on employee table.

EMP => I am using only one table

Query:

SELECT COUNT(E.EMPID)
FROM EMP E, EMP D
WHERE E.WORKDEPT=D.WORKDEPT
RESULT: 298 , WE GOT COUNT OF EMPLOYEES

IF we know dept and emp tables ( 2 Tables)

SELECT COUNT(E.EMPID)
FROM EMP E, DEPT D
WHERE E.WORKDEPT=D.DEPT

RESULT: 298 , WE GOT COUNT OF EMPLOYEES

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.