MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 12th, 2012, 11:33 AM
NightBeam NightBeam is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 NightBeam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 3 m 5 sec
Reputation Power: 0
Unknown column 'InstructorID' in 'on clause'

I have seen this error on this forum before and I have read the help documents and PHP information on changing this statement to 5.*, however, I can't seem to get it right.

What I have is:

$Query = runquery(
'SELECT Dispatch.*, Student.FirstName AS SFirstName, Student.LastName AS SLastName, Instructor.FirstName AS IFirstName, Instructor.LastName As ILastName
FROM Dispatch, Student
LEFT JOIN Instructor ON InstructorID = Instructor.ID
WHERE Student.ID = Dispatch.StudentID ');

Unfortunately I am getting an error, despite how I try to re-write this code which states:

Error was: Unknown column 'InstructorID' in 'on clause'

Can anybody else me better understand why this is occuring? I know that I need to re-write the LEFT JOIN but I am not entirely sure how.

Thank you.

Reply With Quote
  #2  
Old September 12th, 2012, 12:15 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,376 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 35 m 43 sec
Reputation Power: 4140
Quote:
Originally Posted by NightBeam
Can anybody else me better understand why this is occuring? I know that I need to re-write the LEFT JOIN but I am not entirely sure how.
nope, it's your inner join that needs re-writing

as to why it's happening, search this forum for "unknown column" -- this has been answered a couple dozen times since mysql went from version 4 to version 5

which table is InstructorID in?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old September 12th, 2012, 12:20 PM
NightBeam NightBeam is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 NightBeam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 3 m 5 sec
Reputation Power: 0
Thank you for that. I managed to get it to work with a little trial-and-error on the INNER JOIN

I ended up with:

$Query = runquery(
'SELECT Dispatch.*, Student.FirstName AS SFirstName, Student.LastName AS SLastName, Instructor.FirstName AS IFirstName, Instructor.LastName As ILastName
FROM Dispatch
INNER JOIN Student on Student.ID
LEFT JOIN Instructor ON InstructorID = Instructor.ID
WHERE Student.ID = Dispatch.StudentID

Instructor.ID is in the Dispatch Table.

Reply With Quote
  #4  
Old September 12th, 2012, 12:22 PM
NightBeam NightBeam is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 3 NightBeam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 3 m 5 sec
Reputation Power: 0
Sorry, I meant to say that that it was in the Dispatch Table

Reply With Quote
  #5  
Old September 12th, 2012, 12:49 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,376 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 35 m 43 sec
Reputation Power: 4140
Quote:
Originally Posted by NightBeam
FROM Dispatch
INNER JOIN Student on Student.ID
that's incomplete

that will actually join every row of dispatch to every row of student, because Student.ID by itself is going to evaluate as TRUE

your WHERE clause then throws almost all of the joined rows away

what you need to do is move the WHERE condition to that INNER JOIN's ON clause

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Unknown column 'InstructorID' in 'on clause'

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap