How to get unique number of rows from the secondary table
create table pro_category (id primary key, product_id int, category_id int)
insert into pro_category (1, 1, 1)
insert into pro_category (1, 1, 2)
insert into pro_category (1, 2, 1)
insert into pro_category (1, 2, 1)
How to get unique number of rows from the secondary table (e.g. in the above case there are 2 product id's involved so I would like to get an answer of 2).
using count(distinct)
select count(distinct product_id) from pro_category
SELECT COUNT(DISTINCT product_id) FROM pro_category
This will return 2
精彩评论