group mysql subcategories and categories
I went through all the questions on SOF and did my homework but still couldn't find or understand what I am looking for now I have 2 tables 'category' and 'subc开发者_JAVA技巧ategory' they are like:
category:
id (int)
title (varchar)
description (varchar)
subcategory
id (int)
cid (int) // This is same as category id.
title (varchar)
description (varchar)
now I want to join and group both of them how do I do it like this
#category1
-subcat1.1
-subcat1.2
#category2
-subcat2.1
-subcat2.2
and so on..
and I also have seen people call there values like $row['cat.title']
for category title and $row['subcat.title']
as subcategory title and so on.. I think they use 'as' or something like that can anyone help please? I am using php to do the queries.
SELECT sc.title AS subcat_title, c.title AS cat_title
FROM subcategory AS sc
LEFT JOIN category AS c
ON c.id = sc.cid
Select subcat.subcat_title, cat.cat_title from subcategory subcat left join category cat on subcat.cid = cat.id
For for information on storing the hierarchical data checkout the following link
http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
精彩评论