OZONE Asylum
FAQ
Why doesn't DISTINCT help trim down the results returned from my MySQL SELECT statement?
This page's ID:
5699
Search
QuickChanges
Forums
FAQ
Archives
Register
You are editing "Why doesn't DISTINCT help trim down the results returned from my MySQL SELECT statement?"
Who can edit an FAQ?
Anyone registered may edit an FAQ.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
DISTINCT is designed to cut out the repetition of identical rows not just ones that might share the same ID or name. To trim down your results where DISTINCT isn't helping try using the GROUP BY attribute ------------------- Basicly, there's probably something wrong with your query, if you feel the need to use DISTINCT. The number of times I *really* needed to use (the mathematically more correct) DISTINCT, I can count on the fingers of one hand of a guy who worked 40 years in a sawmill... So think about what joins you're doing, how you're filtering and why you're getting 'to many rows' (which can not be fixed by distinct!) (Math note: In set algebra, there is only a 'Select Distinct' since sets by their very definition contain no duplicates. Why the SQL creators went with bags and 'Select All' by default... I don't know. Therefore, 'Select Distinct' only eliminates real duplicates from your result set. ) ---------------------------- Relevant links: Mysql Documentation: [url=http://www.mysql.com/doc/en/SELECT.html]6.4.1 SELECT Syntax[/url] [url=http://www.mysql.com/doc/en/Selecting_columns.html]3.3.4.3 Selecting Particular Columns[/url] [url=http://www.mysql.com/doc/en/Group_by_functions.html]6.3.7 Functions for Use with GROUP BY Clauses[/url] [url=http://www.mysql.com/doc/en/DISTINCT_optimisation.html]5.2.5 How MySQL Optimises DISTINCT[/url] Outside Resources: [url=http://c2.com/cgi/wiki?SelectDistinctIsaCodeSmell]Select Distinct Is a Code Smell[/url] (very informative!) [url=http://c2.com/cgi/wiki?AlwaysUseSelectDistinct]Always Use Select Distinct[/url] _____________________ [internallink=4626]Emperor[/internallink] [small][i](Edited by: [url=http://www.ozoneasylum.com/cgi-bin/ubbmisc.cgi?action=getbio&UserName=Tyberius+Prime]Tyberius Prime [/url] on Sat 24-May-2003)[/i][/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »