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` Link to comment https://forums.phpfreaks.com/topic/231388-return-only-one-row/ 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? Link to comment https://forums.phpfreaks.com/topic/231388-return-only-one-row/#findComment-1190810 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 Link to comment https://forums.phpfreaks.com/topic/231388-return-only-one-row/#findComment-1190815 Share on other sites More sharing options...
PFMaBiSmAd Posted March 22, 2011 Share Posted March 22, 2011 Add - GROUP BY users.id Link to comment https://forums.phpfreaks.com/topic/231388-return-only-one-row/#findComment-1190820 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.