Check this out, sorry for external link but it looks ugly here (maby iam to stupid to format it correct) ^^
Join my irc channel if you like to talk to me
tinyurl.com/ylsf7ef (webchat)
Check this out, sorry for external link but it looks ugly here (maby iam to stupid to format it correct) ^^
Join my irc channel if you like to talk to me
tinyurl.com/ylsf7ef (webchat)
Use joins.
I removed some where conditions for more clarity
SELECT
c.id as c_id,
c.alias as c_alias,
c.title as c_title,
sc.id as sc_id,
sc.alias as sc_alias,
sc.title as sc_title,
a.alias as a_alias,
a.title as a_title,
sa.alias as sa_alias,
sa.title as sa_title
FROM
categories c
LEFT JOIN
articles a
ON
c.id = a.category_id
LEFT JOIN
categories sc
ON
c.id = sc.parent_id
LEFT JOIN
articles sa
ON
sc.id = sa.category_id
ORDER BY
c.rank,
a.rank,
sc.rank,
sa.rank
EDIT: As far as I can see, this is not the case here, but if you want to retrieve some unlimited depth elements, you might want to look at a way to store strong hierarchical data in a relational database.