mysql - 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 pro_category (1, 1, 1) insert pro_category (1, 1, 2) insert pro_category (1, 2, 1) insert pro_category (1, 2, 1) 

how unique number of rows secondary table (e.g. in above case there 2 product id's involved answer of 2).

using count(distinct)

select count(distinct product_id) pro_category 

Comments

Popular posts from this blog

mysql - How to insert just year and month into date field? -

c# - Detect changes in ObjectSet in Entity Framework 4.0? -