Question : inner join with multiple tables

Hi EE,
I have the following query in sql although Im not confident with multiple inner joins.
Can you please help with why this fails.

As you can see I have five tables in the query, outlined below:

article
article_ad
comments
rating
members

the article table is the main data provider.

for every article there is a member id.  the link between member and article is always there so there doesnt need to be a left or right join on this relationship.

The following comments can be summarised to say that the article and member table can have a straight join.  All other tables need to have an inner join to the article table..  When I say inner join I mean that if a record exists in the article id the query must return a table, i.e. all other table data will return null.

an article may or may not have an entry in the article_ad table.  therefore i need a left join between these article and article_ad so that when the article entry does not have an entry in the article_ad table the article_ad columns within the resultant table return NULL.

identical to the previous point, the article may or may not have a comment.  for this reason the relationship between the article and comments table needs a left join so that if there are no comments for the article the comment columns return NULL.

my main cause for posting is im not too sure whether this line from the code snippet

LEFT JOIN      rating as r
ON            r.articleid = article.id,
            members as m

means the members table is included within the left join or not.




Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
SELECT		top 1 *
FROM		(article as a
LEFT JOIN	article_ad as article_ad
ON		article_ad.articleid = article.id)
LEFT JOIN	comments as c
ON		c.articleid = article.id
LEFT JOIN	rating as r
ON		r.articleid = article.id,
		members as m
WHERE		a.memberid = m.id
AND		a.id = c.articleid
AND		a.id = 1
Open in New Window Select All

Answer : inner join with multiple tables

SORRY
select  *
from article A,
article_ad B,
comments C,
rating D,
members E
WHERE A.MEMBER_ID  = E.MEMBER_ID
AND  A.ARTICAL_ID  *= B.ARTICAL_ID
AND A.ARTICAL_ID *= C.ARTICAL_ID
AND A.RATING *= D.RATING


Random Solutions  
 
programming4us programming4us