gvp16 Posted July 8, 2013 Share Posted July 8, 2013 Hi all, I need some help with the following query please, which I am using to consolidate a set of results into a single row via joins, I have done similar queries like this in the past with no problem, but with this query when I am grouping by username or userid the columns are being shown as null SELECT t.user_id, u.username as name, tm.content as monday, tt.content as tuesday, tw.content as wednesday, tth.content as thursday, tf.content as friday, ts.content as saturday, tsu.content as sunday FROM timesheets t LEFT JOIN users u on u.id = t.user_id L EFT JOIN timesheets tm on t.id = tm.id AND WEEKDAY(tm.`date`) = 1 LEFT JOIN timesheets tt on t.id = tt.id AND WEEKDAY(tt.`date`) = 2 LEFT JOIN timesheets tw on t.id = tw.id AND WEEKDAY(tw.`date`) = 3 LEFT JOIN timesheets tth on t.id = tth.id AND WEEKDAY(tth.`date`) = 4 LEFT JOIN timesheets tf on t.id = tf.id AND WEEKDAY(tf.`date`) = 5 LEFT JOIN timesheets ts on t.id = ts.id AND WEEKDAY(ts.`date`) = 6 LEFT JOIN timesheets tsu on t.id = tsu.id AND WEEKDAY(tsu.`date`) = 7 GROUP BY t.user_id See screen shot for example before and after the grouping. Help would be greatly appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/279979-help-with-grouping-issue-please/ Share on other sites More sharing options...
requinix Posted July 8, 2013 Share Posted July 8, 2013 (edited) What do you expect to get by grouping these things together? How does one group NULL and "test"? How would you group "one" and "two"? What you're asking in the query doesn't quite make sense - that's why you're not getting the results you want. [edit] I'll jump to the chase. Have you considered GROUP_CONCAT()? Edited July 8, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/279979-help-with-grouping-issue-please/#findComment-1439977 Share on other sites More sharing options...
gvp16 Posted July 10, 2013 Author Share Posted July 10, 2013 I was hoping to return one row per user with the each day populated. Thanks, I will try Group_concat and report back. Quote Link to comment https://forums.phpfreaks.com/topic/279979-help-with-grouping-issue-please/#findComment-1440165 Share on other sites More sharing options...
requinix Posted July 10, 2013 Share Posted July 10, 2013 Right, but with the screenshot you posted there are multiple rows for the same user+day somewhere. If that wasn't the case then there would be only the one row, as you are expecting to get. Quote Link to comment https://forums.phpfreaks.com/topic/279979-help-with-grouping-issue-please/#findComment-1440199 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.