开发者

How to get unique number of rows from the secondary table

开发者 https://www.devze.com 2023-02-12 16:34 出处:网络
开发者_如何学运维create table pro_category (id primary key, product_id int, category_id int) insert into pro_category (1, 1, 1)
开发者_如何学运维
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

0

精彩评论

暂无评论...
验证码 换一张
取 消