mysql - sql count by value stack by different value -
i have database this:
table1(article) id | name | description | cat_id 0 | val1 | desc1 | 1 1 | val2 | desc2 | 2 2 | val3 | desc3 | 1 3 | val4 | desc4 | 2 4 | val5 | desc5 | 1 5 | val6 | desc6 | 2 6 | val7 | desc7 | 0 table2(categories) id | name 0 | shoe 1 | glove 2 | hat
it should return:
articles_connected | categorie_name 3 | glove 0 | shoe 3 | hat
i tried:
select count(category.id) article_amount, category.name article_table article, category_table category category.id = article.cat_id
this code counts one, doesn't split categories. i'm not sure goes wrong.
try
select count(category.id) article_amount, category.name article_table article, category_table category category.id = article.cat_id group category.name
Comments
Post a Comment