News for hackers. Stuff that matters.
Re:Use SQL subqueries to count distinct 50x faster by schrodinger on Friday January 24, 2014 @11:53AM (#7115883)
FYI, in mssql at least, distinct and group by are entirely equivalent to the query planner. I'm not saying you're wrong though, since group by let's you explicitly pick which columns to go by, whereas distinct uses them all.
Re:Use SQL subqueries to count distinct 50x faster by alinhan on Friday January 24, 2014 @12:52PM (#7116233)
I don't understand what you mean by "group by let's you explicitly pick which columns to go by, whereas distinct uses them all". Can you give an example?
Re:Use SQL subqueries to count distinct 50x faster by schrodinger on Friday January 24, 2014 @03:40PM (#7117835)
select userid, name from users group by userid, name

is equivalent to

select distinct userid, name from users

It's easy to add another column to the "distinct" based query and change the behavior accidentally. With the "group by" query, you'd get an error saying that the new column needs to be either aggregated or added to the group by.