Einzelnen Beitrag anzeigen
Alt 22.12.2006, 13:24   #2
jak
Inventar
 
Registriert seit: 13.06.2001
Beiträge: 1.830


Standard

Die Lösung die ich verwendet habe sind zwei SELECTs die mit UNION zusammen gefasst werden. Das ist allerdings eher mühsam, da die WHERE statements für beide SELECTs angepasst werden müssen.

Von http://dev.mysql.com/doc/refman/4.1/en/union.html
Zitat:
Posted by Kim Mihaly on October 4 2006 5:35am

For an app I was writing I needed to list both parent & child for a 2 level tree - the first half of the union returns all the parents , the second all the children for these parents - as I was using the pear html_pager I also added a limit clause....

select parent.categoryid, parent.categoryname, parent.sequence as seq, parent.categoryid as id, '' as name, 0 as seq1
from category as parent
where parent.isasubcategoryof = 0
union
select parent.categoryid, parent.categoryname, parent.sequence as seq, child.categoryid as id, child.categoryname as name, child.sequence as seq1
from category as parent, category as child
where (child.isasubcategoryof = parent.categoryid)
order by seq, seq1
jak
____________________________________
Join the DNRC | Godwin\'s Law (thx@stona)
Documentation is like sex: If it\'s good, it\'s very, very good. If it\'s bad, it\'s better than nothing.
\"In theory, theory and practice are the same. In practice, they are not\" (Lawrence Berra)
jak ist offline   Mit Zitat antworten