Jump to content

joining lines located in the same table?


fwapah

Recommended Posts

i have a review system that is setup but it's all in one table. each reviewer has a unique id and 1-5 packets to review. it looks like this, where each reviewer/packet combo has its own line. not the best situation, i know.

 

idreviewerlastpnumpauthorscore

5smith54wilson2.0

5smith99marks1.0

7jones99marks1.3

 

what i would like to do is be able to combines all of the records with an identical grant number and list their separate scores in the row, so that it looks something like this:

 

pnumpauthorscore1reviewer1score2reviewer2

54wilson2.0smith[/td][td]

99marks1.0smith1.3marks

 

pleeeeeease tell me one of you geniuses can figure this out! thank you so much!

Link to comment
Share on other sites

It's a self join, i.e. JOIN table1 ON table1.

 

Given that you're identity is the "id" column you'll be joining on that. I'm assuming you know how to do a join so i'll leave you to figure out the exact SQL.

 

However, I think what you're ideally looking for is a cross-tab. Needless to say, the self-join will suffice for now.

 

p.s. the join is a LEFT JOIN

Link to comment
Share on other sites

thanks so much.. sorry for my delayed response. i can still do a left join even though the pnum and id are both not unique? 

 

every pnum/id combo has its own line in the table. i need a join where the pnum is listed with its three different scores.

 

thanks so much for your counsel!!!

Link to comment
Share on other sites

i know, i know, sorry.. it's hard to explain. here is a quick summary, similar to the one above but arranged a little differently.

 

i have:

 

pnumpauthorscoreidreviewerlast

54wilson2.05smith

99marks1.05smith

99marks1.37jones

 

as you can see, the pnum (packet number) and id (of the reviewer of the packet [pnum]) are not unique in this table.

 

i need to display a table that lists each packet (group by pnum) in a line with the three different scores from the three different IDs matched with that pnum.

 

pnumpauthorscore1reviewer1score2reviewer2

54wilson2.0smith[/td][td]

99marks1.0smith1.3marks

 

thank you for taking a look at my messy table and thank you so much for your help!

Link to comment
Share on other sites

I've tried to think about this a million different ways, but can't put my mind around how to accomplish this.. hence my posting here. if you have any tips on how to "massage," please let  me know, because I am absolutely stumped all around.

 

thanks.

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.