KitCarl Posted April 28, 2010 Share Posted April 28, 2010 I have a table TrialClass with columns ClassID(autoincrement), ListingID, ClassID, ClassDate, PreamesureTimeID, ClosingTimeID, Judge1ID, Judge2ID The PremeasureTimeID & ClosingTimeID are integer columns that both reference the ID column of the Close Table which has a CloseHour column with a list of times on the half hour. The Judge1ID & Judge2ID both reference the ID column of the Person Table and I Concat columns to generate names I need to write a query that gives me: {ClassName, ClassDate(these first two I can handle generation the referenced field)}, PremeasureTime, ClosingTime, Judge1 (Name from Person Table), Judge2 (Name from person Table) Where ListingID = 'variable' I'm lost with the more than one reference to the same column more than once. Please lead me in the right direction or tell me if the table design will cause me trouble in the future. I'm hoping to learn as well as have it solved so please give an explanation and hopefully I will understand for next time. If I need to ad any more information just ask. Quote Link to comment https://forums.phpfreaks.com/topic/199994-having-two-colums-in-same-table-reference-a-single-column-in-another-table/ Share on other sites More sharing options...
jdavidbakr Posted April 28, 2010 Share Posted April 28, 2010 I think what you're wanting to do is use aliases select Judge1.name, Judge2.name from TrialClass, person Judge1, person Judge2 where Judge1.ID = TrialClass.Judge1ID and Judge2.ID = TrialClass.Judge2ID Basically that gives you two copies of the "person" table named "Judge1" and "Judge2" that act independently of each other. Quote Link to comment https://forums.phpfreaks.com/topic/199994-having-two-colums-in-same-table-reference-a-single-column-in-another-table/#findComment-1050104 Share on other sites More sharing options...
ignace Posted April 28, 2010 Share Posted April 28, 2010 The Judge1ID & Judge2ID Are signs of poor database design. Quote Link to comment https://forums.phpfreaks.com/topic/199994-having-two-colums-in-same-table-reference-a-single-column-in-another-table/#findComment-1050108 Share on other sites More sharing options...
Mchl Posted April 28, 2010 Share Posted April 28, 2010 The Judge1ID & Judge2ID Are signs of poor database design. Not if the number of judges is unlikely to ever change. Quote Link to comment https://forums.phpfreaks.com/topic/199994-having-two-colums-in-same-table-reference-a-single-column-in-another-table/#findComment-1050111 Share on other sites More sharing options...
KitCarl Posted April 29, 2010 Author Share Posted April 29, 2010 jdavidbakr, I was able to make it work and gain some understanding with that guidance, Thank You Very Much. ignace & Mchl, thanks for the input. Actually this event does always requires two judges, but the note about poor database design has me thinking about reworking it in case I later want to include other events that have different requirements. I discovered this board a few days ago and it is obvious it contains many knowledgeable helpful people. Quote Link to comment https://forums.phpfreaks.com/topic/199994-having-two-colums-in-same-table-reference-a-single-column-in-another-table/#findComment-1050293 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.