Discussion: Child and parent rows
Afficher un message
Vieux 27/09/2007, 10h30   #8
João Morais
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Child and parent rows

SELECT m1.id, m1.idParent, m1.name, m1.position
FROM menuitens m1
LEFT JOIN menuitens m2 ON m1.id=m2.id AND m1.idParent<m2.idParent
WHERE m2.idParent IS NULL
ORDER BY m1.position, m1.idParent

This one almost does what I need, result provided:

id | idParent | name | position
5 0 a 1
12 5 a1 1
13 12 a11 1
9 13 a111 1
14 0 b 2
10 5 a2 2
11 5 a3 3

(id 14 should be at the bottom)

When it should be:

id | idParent | name | position
5 0 a 1
12 5 a1 1
13 12 a11 1
9 13 a111 1
10 5 a2 2
11 5 a3 3
14 0 b 2

Hope someone can me on this, cause I dont want to use recursive
solutions since this script will be used often and thats not good for
the server.

  Réponse avec citation
 
Page generated in 0,05181 seconds with 9 queries