mysql - How to select records that contains IDs but not contains only IDs from this same list -
i want have selected records contains selected ids doesn't contains these ids same lists.
my sql code:
select question_id, person_id `answers` `person_id` in ('9', '18')
results:
2, 9 2, 18 4, 9 4, 18 5, 18 6, 9
expected results:
5, 18 6, 9
full sql query:
select id, name questions id not in ('3', '13') , exists (select `id` `answers` `answers`.`question_id` = `questions`.`id` , `person_id` in ('9', '18')) order rand() limit 1
you try using group , having
select question_id, person_id `answers` person_id` in ('9', '18') group question_id having count(distinct person_id) = 1
selecting rows person_id in set match 1 value
Comments
Post a Comment