category and sub category traversal
| From: | ceo at l-i-e dot com | Date: | Tue, 02 Dec 2008 14:57:39 +0000 |
| Subject: | category and sub category traversal | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-283989@lists.php.net to get a copy of this message | ||
Google for "SELF JOIN"
You also may want to just put the parent_id in the category table, rather than a second table.
Your query would then look like this:
select parent.tid, child.tid
from term_data as parent, term_data as child
where child.parent_id = parent.tid
and child.vid = 16
order by weight, name
WARNING:
If term_data is a LARGE table, this query could become problematic.
You'll need an index on (tid, vid, weight, name), I think.
Follow-up with more questions to the MySQL (or other SQL) mailing list please, as there's no
actual PHP in this question.