Why can't we use count(distinct *)
in SQL? As in to count all distinct rows?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
You can indeed.
If you've got an identifier, though, you won't have any entirely distinct rows. But you could do for instance:
Although I strongly suggest that you re-think any queries that use
DISTINCT
. In a large percentage of cases,GROUP BY
is more appropriate (and faster).EDIT: Having read the question comments, I should point out that you should never ask the DBMS to do more work than actually needs doing to get a result. If you know in advance that there will not be any duplicated rows in a table, then don't use
DISTINCT
.You can select all the columns in your table and group by...