write a sql query each employee have more than one department id ? [Resolved]

Posted by Kasani007 under Sql Server on 7/11/2014 | Points: 10 | Views : 2464 | Status : [Member] | Replies : 3
write a sql query each employee have more than one department id ?




Responses

Posted by: Bandi on: 7/12/2014 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
fixed small typo in the above solution....

SELECT EMPLOYEE_ID , COUNT(EMPLOYEE_ID ) AS NUMBER_OF_OCCURANCES FROM EMPLOYEES GROUP BY EMPLOYEE_ID HAVING COUNT(DEPARTMENT_ID) > 1

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/12/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
try this

SELECT EMPLOYEE_ID , COUNT(EMPLOYEE_ID ) AS NUMBER_OF_OCCURANCES
FROM EMPLOYEES
GROUP BY EMPLOYEE
HAVING COUNT(DEPARTMENT_ID) > 1



Thank you for posting at Dotnetfunda
[Administrator]

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/13/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Thanks Bandi

Thank you for posting at Dotnetfunda
[Administrator]

Kasani007, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response