Mysql - Get All Records That Have More Than 1 Record For The Same Id
I apologize in advanced if I am not explaining this correctly. I can barely explain it in english terms, let alone in a mysql query. I am trying to get the list of response_set_ids
Solution 1:
The simplest method doesn't use a subquery:
SELECTDISTINCT response_set_id
FROM responses
GROUPBY response_set_id, question_id
HAVINGCOUNT(*) >1;
This is one of the very, very few instances where select distinct is used (appropriately) with group by.
Solution 2:
selectdistinct response_set_id from (
select response_set_id , question_id
from
responses
groupby
response_set_id, question_id
havingcount(*)>1) a
Post a Comment for "Mysql - Get All Records That Have More Than 1 Record For The Same Id"