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 Quote 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. Quote 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! Quote 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 Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/278179-query-help/#findComment-1431361 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.