[UPHPU] OT: SQL Query Question
Brandon Stout
hplsbyufan at imapmail.org
Wed May 31 12:54:25 MDT 2006
SELECT DISTINCT works on every column - if the entire row is unique, it
gets listed. However, if you are using GROUP BY, I believe it should do
the same thing. I use GROUP BY for queries that COUNT, SUM, etc.
(aggregate functions), and SELECT DISTINCT for normal, non-GROUP BY
queries. Some pages that may help:
SELECT syntax: http://dev.mysql.com/doc/refman/5.0/en/select.html
(search the page for DISTINCT and or GROUP BY)
DISTINCT optimization:
http://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html
GROUP BY (aggregate) functions:
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
GROUP BY modifiers:
http://dev.mysql.com/doc/refman/5.0/en/group-by-modifiers.html
GROUP BY and HAVING:
http://dev.mysql.com/doc/refman/5.0/en/group-by-hidden-fields.html
GROUP BY optimization:
http://dev.mysql.com/doc/refman/5.0/en/group-by-optimization.html
Brandon Stout
http://mscisl.org
Jonathan Grotegut wrote:
> I am using MySQL. I took the SUM off the query so I could find out
> what the problem is and forgot to put it back on, sorry. When I put
> the SUM on for those two fields it is still including the raid twice
> (or more) whenever the player gets more than one item on a raid (which
> happens fairly often).
>
> Does anyone know if you do SELECT DISTINCT does it do it on every
> column of data or on one particular column?
>
> Thanks again,
> Jonathan
>
> On 5/31/06, Brandon Stout <hplsbyufan at imapmail.org> wrote:
>> If you do SUM(`items`.`dkpcost`), and/or
>> SUM(`raidattendence`.`PointsEarned`), you must use GROUP BY before you
>> use ORDER BY, and if you do GROUP BY, that often makes every row
>> distinct. If you are summing things at another level than the query,
>> you should probably try SELECT DISTINCT, which ensures every row is
>> unique. Are you using MySQL, PostgreSQL, or some other database?
>>
>> Brandon Stout
>> http://mscis.org
> <snip>
>
> _______________________________________________
>
> UPHPU mailing list
> UPHPU at uphpu.org
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net
More information about the UPHPU
mailing list