I have 2 tables, Products, and Genre.. In the products table its all the info on the product including two genres, (genre_id and genre_id2), only the first one is required, so the second could have null values
in the Genre table I have all the possible genres names with an ID to relate to the genres ID's of the product table
TABLE PRODUCTS -------------- id product_name genre_id genre_id2 ------------------------------------------------- 1 product 1 2 2 product2 2 3 product3 1 4 4 product4 3 4 TABLE GENRE ----------- id genre_name ------------------------------------------------- 1 genre1 2 genre2 3 genre3 4 genre4
I want to select all the different genres and see how many products i have of that genre
something like this
RESULT
------
genre_id count
-----------------------
1 2
2 2
3 1
4 2
I have this statement
SELECT DISTINCT p.genre_id AS genre, g.genre_name, COUNT(p.genre_id) AS cnt
FROM products AS p
JOIN genre AS g
ON p.genre_id=g.id
GROUP BY genre_id
ORDER BY cnt DESC
but only works on genre_id and i dont know how to incorporate genre_id2 in this statement and add the counts that coincide with genre_id and list the different ones