farahZ Posted May 19, 2013 Share Posted May 19, 2013 i'm trying to view in a table: daytime --- meal --- calories the table in the database has (fooddiary) ID--Date---DayTime---Food--Calories and table: food FID---FoodName---Size---Calories i'm not able to show the food a person ate for each meal !! DayTime and Sum of Calories were working fine,, now trying to add the food a user ate corresponding to the day time.. please help me SELECT fe.DayTime, SUM(f.Calories) as Calories, (select FoodName from fooddiary where DayTime=fe.DayTime) as meal FROM fooddiary fe INNER JOIN food f USING (Food) WHERE fe.ID= 111 And fe.Date='$date' GROUP BY fe.DayTime Link to comment https://forums.phpfreaks.com/topic/278179-query-help/ Share on other sites More sharing options...
Jessica Posted May 19, 2013 Share Posted May 19, 2013 Don't do it as a sub-select, do it as a regular join. Link to comment https://forums.phpfreaks.com/topic/278179-query-help/#findComment-1431033 Share on other sites More sharing options...
farahZ Posted May 19, 2013 Author Share Posted May 19, 2013 dont wanna mess up the daytime and calories.. they are working fine here! Link to comment https://forums.phpfreaks.com/topic/278179-query-help/#findComment-1431034 Share on other sites More sharing options...
farahZ Posted May 20, 2013 Author Share Posted May 20, 2013 can it be using like this? SELECT fe.DayTime, SUM(f.Calories) as Calories, GROUP_CONCAT(select Food from fooddiary where DayTime=fe.DayTime and Date=2013-05-17) FROM fooddiary fe INNER JOIN food f USING (Food) WHERE fe.ID= 111 And fe.Date=2013-05-17 GROUP BY fe.DayTime Link to comment https://forums.phpfreaks.com/topic/278179-query-help/#findComment-1431237 Share on other sites More sharing options...
jazzman1 Posted May 21, 2013 Share Posted May 21, 2013 can it be using like this? No, it's wrong. Start from here. Link to comment https://forums.phpfreaks.com/topic/278179-query-help/#findComment-1431361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.