I have two tables, "name" and "address". I would like to list the last_name
and joined address.street_address
of all last_name
in table "name" that occur more than once in table "name".
The two tables are joined on the column "name_id".
The desired output would appear like so:
213 | smith | 123 bluebird |
14 | smith | 456 first ave |
718 | smith | 12 san antonia st. |
244 | jones | 78 third ave # 45 |
98 | jones | 18177 toronto place |
Note that if the last_name "abernathy" appears only once in table "name", then "abernathy" should not be included in the result.
This is what I came up with so far:
SELECT name.name_id, name.last_name, address.street_address, count(*)
FROM `name`
JOIN `address` ON name.name_id = address.name_id
GROUP BY `last_name`
HAVING count(*) > 1
However, this produces only one row per last name. I'd like all the last names listed. I know I am missing something simple. Any help is appreciated, thanks!