Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count distinct records (all columns) not working [duplicate]

what's proper syntax for

count (distinct *) from t1

I am getting he following error:

[Err] 42000 - [SQL Server]Incorrect syntax near the keyword 'distinct'.

like image 373
Eduardo Dennis Avatar asked Dec 16 '13 20:12

Eduardo Dennis


People also ask

Does distinct work on all columns?

Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause.

How can I get distinct COUNT of multiple columns in SQL?

select count(distinct col1 || '-' || col2) from mytable; or use a subquery: select count(*) from (select distinct col1, col2 from mytable);

Does distinct work on multiple columns?

The DISTINCT clause can be applied to one or more columns in the select list of the SELECT statement.

How do I COUNT distinct 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.


1 Answers

select count(*)
from
(
   select distinct * from your_table
) x
like image 122
juergen d Avatar answered Oct 04 '22 20:10

juergen d