join - MySql Get records only from child table where the parent key has multiple values -
i have 2 tables parent , child. parent has field called unique_id , child has field called parent_unique_id , foreign key in child table. parent table has 4 records same unique_id , child table has 5 records same unique_id.
when join them records, getting total of 20 records each 5 records of child table repeating 4 times.
the query using
select c.* child c join parent p on c.parent_unique_id = p.unique_id
i tried left join still getting 20 records repeated.
one method use in
or exists
:
select c.* child c c.parent_unique_id in (select p.unique_id parent p);
of course, slap select distinct
on query. however, requires , unnecessary processing.
Comments
Post a Comment