Jump to content

Help with grouping issue please


gvp16

Recommended Posts

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.

 

 

post-62229-0-72485900-1373319743_thumb.jpg

Link to comment
Share on other sites

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 by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.