I have two tables, one is employees and another one is details. Here I need the query to display the employees who are having multiple phone numbers.
Employees table:
employee_id Name salary
----------- ------- --------------------
0001 John 100000
0002 Peter 50000
0003 Russel 60000
0004 Bill 60000
0005 Patrick 90000
Details Table :
employee_id Address phone
----------- ------- --------------------
0001 USA 854646542
0002 Germany 656562354
0001 USA 465222333
0004 China 888444444
0005 Canada 012445869
0005 Canada 789875877
0003 Japan 444555807
From this I need to display employees who are having more than one phone number so the expected output should be
employee_id Name phone
----------- ------- --------------------
0001 John 854646542
0001 John 465222333
0005 Patrick 012445869
0005 Patrick 789875877
Query I have tried :
SELECT COUNT(*)
FROM (
SELECT employee_id, COUNT(*) AS CNT
FROM details
GROUP BY employee_id
) AS T
WHERE CNT > 1