Forum Moderators: open

Message Too Old, No Replies

Multiple Inner Join difficulties

Inner Join

         

Frasnko

8:34 pm on Apr 30, 2007 (gmt 0)

10+ Year Member



i have three tables that i am trying to pull from in one query, it seems like a simple task. Yet i cannot get it to work! Here is a rough idea of the table structure
portfilio
-id
-img
-category

portfolio_cats
-id
-cat

portfolio_comments
-id
-portfolio_id
-user_id
-comment

I am using the following select statement:

SELECT portfolio.id, portfolio.img, portfolio.title,portfolio.public,portfolio.descrip, portfolio_cats.cat
FROM `portfolio_cats`
INNER JOIN portfolio ON portfolio_cats.id = portfolio.category
INNER_JOIN portfolio_comments ON portfolio.id = portfolio_comments.portfolio_id

I have tried various variations on this select to try and address the error that i am getting:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER_JOIN portfolio_comments ON portfolio_cats.id = portfolio_comments.portfoli...' at line 4

I have searched books and online postings relating to this multiple Inner Join syntax,

select stuff
from A
inner join B on A.id = B.Aid
inner join C on B.id = C.Bid

So i understand the succession of tables in the innerjoin, can anyone suggest how i might arrange my query? Or help me to understand why it won't work?

Many thanks!

[edited by: Frasnko at 8:47 pm (utc) on April 30, 2007]

FalseDawn

11:37 pm on May 3, 2007 (gmt 0)

10+ Year Member



Assuming the "INNER_JOIN" with an underscore was a typo, you might have to bracket the joins, thus:

SELECT portfolio.id, portfolio.img, portfolio.title,portfolio.public,portfolio.descrip, portfolio_cats.cat
FROM ((`portfolio_cats`
INNER JOIN portfolio ON portfolio_cats.id = portfolio.category)
INNER JOIN portfolio_comments ON portfolio.id = portfolio_comments.portfolio_id)