Show only one child row per parent row

from the Artful Common Queries page

Given tables parent(id int not null primary key, etc...) and child (id int not null primary key, pid int not null references parent (id), etc...), how do we write a query that retrieves only one child row per pid even when the child table has multiple matching rows? MySQL permits use of GROUP BY even when the SELECT list specifies no aggregate function, so this will work:
from parent p 
join child c on
group by;
But is it accurate? No, because it displays only the first value it happens to find. For further discussion see "Within-group aggregates".

Last updated 22 May 2009