sphinx9999 Posted February 14, 2008 Share Posted February 14, 2008 Which do you think is better, DISTINCT or GROUP BY? SELECT DISTINCT id FROM phrase WHERE campaign LIKE 'proper%' or SELECT id FROM phrase WHERE campaign LIKE 'proper%' GROUP BY advert_id I've asked this question before and received the following answer from a reliable source: "When there's just one column it doesn't matter". Do you agree? Quote Link to comment https://forums.phpfreaks.com/topic/91044-distinct-or-group-by/ Share on other sites More sharing options...
Daniel0 Posted February 14, 2008 Share Posted February 14, 2008 It depends on what you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/91044-distinct-or-group-by/#findComment-466826 Share on other sites More sharing options...
aschk Posted February 14, 2008 Share Posted February 14, 2008 GROUP BY Quote Link to comment https://forums.phpfreaks.com/topic/91044-distinct-or-group-by/#findComment-466833 Share on other sites More sharing options...
jaymc Posted February 15, 2008 Share Posted February 15, 2008 Benchmark it ;-) Â phpmyadmin is good, it tells you time taken to execute a query Quote Link to comment https://forums.phpfreaks.com/topic/91044-distinct-or-group-by/#findComment-467726 Share on other sites More sharing options...
freenity Posted February 26, 2008 Share Posted February 26, 2008 I know old topic, but have a look at this: http://gwphp.feudal-times.net/?p=5 benchmarked and everything  Guess who wins Quote Link to comment https://forums.phpfreaks.com/topic/91044-distinct-or-group-by/#findComment-477195 Share on other sites More sharing options...
fenway Posted February 27, 2008 Share Posted February 27, 2008 This is mainly because distinct is a filesort operation which group by has the chance to use an index or some temporary filesorting on smaller sets along the way. Quote Link to comment https://forums.phpfreaks.com/topic/91044-distinct-or-group-by/#findComment-478286 Share on other sites More sharing options...
goldfiles Posted April 16, 2008 Share Posted April 16, 2008 Group By usually Quote Link to comment https://forums.phpfreaks.com/topic/91044-distinct-or-group-by/#findComment-518202 Share on other sites More sharing options...
abs0lut Posted August 24, 2008 Share Posted August 24, 2008 i will not use distinct anymore Quote Link to comment https://forums.phpfreaks.com/topic/91044-distinct-or-group-by/#findComment-624209 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.