Wednesday, 15 June 2011

SQL count(*) and distinct -


Why can not we use count (different *) in SQL? As the count of all the different rows?

  Select (*) from (different from MyTable) as T  

However, I firmly recommend that you think any queries that use DISTINCT again. In a large percentage of cases, GROUP BY is more appropriate (and faster).

Edit: After reading the question comments, I should say that you should never get results Ask DBMS to do more work than actually need to. If you already know that there are no duplicated rows in the table, do not use DISTINCT .


No comments:

Post a Comment