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
https://forums.phpfreaks.com/topic/148852-joining-lines-located-in-the-same-table/
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

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!!!

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.