mysql query: SELECT DISTINCT column1, GROUP BY column2
Posted
by Adam
on Stack Overflow
See other posts from Stack Overflow
or by Adam
Published on 2010-03-20T15:02:42Z
Indexed on
2010/03/20
15:11 UTC
Read the original article
Hit count: 353
Right now I have the following query:
SELECT name, COUNT(name), time, price, ip, SUM(price) FROM tablename WHERE time >= $yesterday AND time <$today GROUP BY name
And what I'd like to do is add a DISTINCT by column 'ip', i.e.
SELECT DISTINCT ip FROM tablename
So my final output would be all the columns, from all the rows that where time is today, grouped by name (with name count for each repeating name) and no duplicate ip addresses.
What should my query look like? (or alternatively, how can I add the missing filter to the output with php)?
Thanks in advance.
© Stack Overflow or respective owner