mysql - Selecting two colums in two tables (one column being the same in both tables) -
i have 2 tables - category , subcategory, both have id_category. in other words, in category:
id_category: 3 category_name: security
and in subcategory:
id_subcategory: 1 id_category: 3 subcategory_name: antivirus
i have multiple items in same category, want list items this: security: antivirus, spyware, firewall.
also, want same other categories, in end list this: security: antivirus, spyware, firewall. multimedia: audio, video, images.
i'm not sure how that. searched around , tried different things nil worked me.
you can utilize group_concat aggregate function:
select category_name, group_concat(subcategory_name) category inner bring together subcategory on subcategory.id_category=category.id_category grouping category_name
see fiddle here.
mysql
No comments:
Post a Comment