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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -