how to which person has all the things ? mysql -
below table
person things tv car mobile house b tv c tv c car c mobile c house d tv e tv f tv
above can see , c has things.
as per book example able find thing every person has ? using below query ,
select things tbl_happiness x not exists ( select person tbl_happiness y not exists ( select 1 tbl_happiness z z.person = y.person , z.things = x.things ) );
is possible use same query change in alias name , find
which person has things ?
i approach these "set-within-sets" queries using group by
, having
:
select person table t group person having count(distinct thing) = (select count(distinct thing) table t);
if there no duplicates, can use:
having count(*) = (select count(distinct thing) table t);
Comments
Post a Comment