MySQL Forums
Forum List  »  General

Re: LIMIT in JOIN
Posted by: Felix Geerinckx
Date: January 16, 2007 06:59AM

Amir Habibi Wrote:

> If we don't have the 'sort' column, or if the 'sort' column is bad filled (for example
> 1,2,2,2,4) is it possible to acheive this ?

Perhaps you can use the child.id column as a sort column:
SELECT
    parent.id, parent.name,
    c1.id, c1.name
FROM parent
JOIN child c1 ON c1.parent_id = parent.id
LEFT JOIN child c2 ON c2.parent_id = c1.parent_id AND c2.id < c1.id
GROUP BY parent.id, parent.name, c1.id, c1.name
HAVING COUNT(c2.id) < 2
ORDER BY parent.name, c1.name;

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
January 16, 2007 03:26AM
January 16, 2007 03:30AM
January 16, 2007 03:43AM
January 16, 2007 03:51AM
January 16, 2007 05:48AM
January 16, 2007 06:29AM
January 16, 2007 06:53AM
Re: LIMIT in JOIN
January 16, 2007 06:59AM
January 16, 2007 07:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.