unemployment Posted March 22, 2011 Share Posted March 22, 2011 Why does this return only 1 row? SELECT SUM(TIMESTAMPDIFF(DAY,`transactions`.`buy_date`,`transactions`.`end_date`)) AS `time_left`, `users`.`id` FROM `transactions` LEFT JOIN `users` ON `users`.`id` = `transactions`.`uid` Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 22, 2011 Share Posted March 22, 2011 Because SUM() is an aggregate function that is rolling up all the results into one row. What result do you want to get? Quote Link to comment Share on other sites More sharing options...
unemployment Posted March 22, 2011 Author Share Posted March 22, 2011 I want to get the sum for each user.id Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 22, 2011 Share Posted March 22, 2011 Add - GROUP BY users.id Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.