0

enter image description here

These are two tables 1. emp_table, 2. phone_table. How to get employee name and id who have two phone numbers in second table

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
raveendra
  • 13
  • 1

1 Answers1

0
SELECT t1.id,
       t1.name
FROM emp_table t1
INNER JOIN                   -- the join will remove employees who do not have
(                            -- two phone numbers in phone_table
    SELECT Id
    FROM phone_table         -- this query identifies all employees
    GROUP BY Id              -- having two phone numbers in phone_table
    HAVING COUNT(*) = 2
) t2
    ON t1.id = t2.Id
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360