View Single Post
Old 02-24-2013, 09:00 AM   PM User | #4
Celtboy
Regular Coder

 
Join Date: May 2002
Location: Virginia, USA
Posts: 620
Thanks: 0
Thanked 6 Times in 6 Posts
Celtboy is an unknown quantity at this point
Oh. Yeah. once you toss in a COUNT, it aggregates everything into a single row. The solution would be to add a GROUP BY clause...or actually that will probably not give you the correct row count. You'll either need to use a subquery, or join the table on itself.

This isn't exactly elegant (i'd prefer multiple SQL queries) but...

Code:
SELECT username, DATE_FORMAT(join_date, "%d/%m/%y") as join_date_str,
(SELECT COUNT(*) FROM users) AS num_users
FROM users
ORDER BY join_date
DESC
LIMIT 5;
should do it.
Celtboy is offline   Reply With Quote
Users who have thanked Celtboy for this post:
LearningCoder (02-24-2013)