Forum Moderators: open

Message Too Old, No Replies

GROUP BY problem

         

ozzyman

10:30 am on May 10, 2006 (gmt 0)

10+ Year Member



I want to take last 10 voted members by excluding same members.
Table is like this:

id / member / vote
1 / 10 / 1
2 / 15 / 0
3 / 32 / 0
4 / 10 / 0

I think this query is ok but not working:
SELECT member, COUNT(*) FROM table GROUP BY member ORDER BY id DESC LIMIT 10

What do you think?

ChadSEO

2:43 pm on May 10, 2006 (gmt 0)

10+ Year Member



ozzyman,

It will probably complain about the ORDER BY clause, specifically the 'id' - this might work better:

SELECT member, COUNT(*) FROM table GROUP BY member ORDER BY max(id) DESC LIMIT 10

Hope that helps!

Chad

ozzyman

4:44 pm on May 10, 2006 (gmt 0)

10+ Year Member



Thanks chad but it gives "Invalid use of group function" error
Any idea?

Demaestro

4:46 pm on May 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try:

SELECT member, COUNT(member) FROM table GROUP BY member ORDER BY max(id) DESC LIMIT 10

ozzyman

5:24 pm on May 10, 2006 (gmt 0)

10+ Year Member



Damaestro it give same error above.

I found the solution from another board. Here is the query maybe helps somebody else too:


select member
, max(id) as last_id
from daTable
group
by member
order
by last_id desc limit 10