Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - how to count unique combination of columns

Tags:

sql

oracle

I'm not sure if this is possible but I want to count the number of unique value in a table. I know to count the number of unique folderIDs I do:

select count(folderid) from folder 

but I want the count of the number of unique combination of folderid and userid in the folder table. Is there a way to do this?

like image 791
Kaskade Avatar asked Dec 15 '11 11:12

Kaskade


People also ask

How do I count the number of unique columns?

The COUNT DISTINCT function returns the number of unique values in the column or expression, as the following example shows. SELECT COUNT (DISTINCT item_num) FROM items; If the COUNT DISTINCT function encounters NULL values, it ignores them unless every value in the specified column is NULL.

How do I get unique values from two columns in SQL?

SQL Server – Using Select Distinct Statement Using Distinct statement we can retrieve distinct values from a table. Distinct eliminates all the duplicate records for a column or columns and returns only distinct or unique records for them. Distinct statement can be used over a single column or multiple columns.…


2 Answers

select count(*) from (   select distinct folderid, userid from folder ) 
like image 180
tobiasbayer Avatar answered Sep 18 '22 17:09

tobiasbayer


select count(*) from (     select folderId, userId     from folder     group by folderId, userId ) t 
like image 43
Michał Powaga Avatar answered Sep 18 '22 17:09

Michał Powaga