2011/03/10

sql get all child cat by parent id

改少少就可以拎哂所有child
平時冇咩用, 但searching 好有用 =]

SELECT t1.* FROM category AS t1
LEFT JOIN category AS t2 ON t2.category_id= t1.parent
LEFT JOIN category AS t3 ON t3.category_id =t2.parent
WHERE 
(t1.category_id = [child_id] OR t2.category_id = [child_id] OR t3.category_id = [child_id])
 ORDER BY t1.LEVEL

沒有留言:

發佈留言