Reputation: 1
Been bothered with this for awhile now and i think it might be how i have the joins set up.
I have two tables. Ones is called info which contains all of a users contact information. My second table called numbers has all the phonenumbers for different users. They are related by the primary id of info to the info_id of phonenumbers. I want them to join based on this relationship and I want all the phonenumbers under phonenumbers to join into the single phonenumbers column in info. The current join i am using is this.
SELECT phonenumbers p, info i FROM i.phonenumbers
INNER JOIN p.workphone
ON i.PID=p.info_id
INNER JOIN p.homephone
ON i.PID=p.info_id
INNER JOIN p.mobilephone
ON i.PID=p.info_id
all i get is the SELECT comman is deneied to user on database workphone that isnt evena database.
table info: PID, firstname, lastname, address, email, phonenumbers,
table phonenumbers: PID, workphone, homephone, mobilephone, info_id,
The syntax for a join would be nice. All the tutorials just give examples and not an explanation of what the different pieces are.
Upvotes: 0
Views: 261
Reputation: 360672
JOIN syntax is
TYPE_OF_JOIN database.table ON field = field
Since you have
JOIN p.workphone ON i.PID = p.info_id
You're actually telling the DB to look for a database named p
, which contains a table workphone
.
Doesn't matter that you've created an alias p
up in your SELECT fields list. That's a field alias, and they NOT the same as a table alias.
Upvotes: 1