SQL Query Help on separating return result

54 Views Asked by At

Example: On the phone table, someone has two phone number SQL would give me the a second row of the same person with different phone number instead of second column. What query do I use to check if person_id appears more than once insert second row of data in a separate column?

I hope this make sense. Thanks in advance!

1

There are 1 best solutions below

1
On

Try something like this:

SELECT person_id, COUNT(person_id) AS 'PersonIDCount' FROM phone_table
GROUP BY person_id
HAVING COUNT(person_id) > 1

The query will return all records where the same person_id key was inserted more than once.