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?
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.
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.…
select count(*) from ( select distinct folderid, userid from folder )
select count(*) from ( select folderId, userId from folder group by folderId, userId ) t
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With