postgresql - SQL Retrieve rows that have all rows from other table -
i facing issues retrieving data using sql in 1 specific scenario:
suppose have following tables:
a
(id, attr_a, attr_b);b
(id, attr_d, attr_e);c
(id_a, id_b);
as can see, table c
have fk
referencing id table a
, , referencing id table c
.
i need retrieve table a
rows each a
row relates every b
row.
in real life scenario, assuming a
means users, b
means privileges, , c
many many entity relates users privileges, want users have privileges
select a.* join c on id_a = id group id having count(id) = (select count(*) b)
there no need use subquery because a.id
primary key (or unique @ least) column referenced c.id_a
.
Comments
Post a Comment