Simple SQL question

B

Bonzol

Hey there, been doing some basic SQL for a while now, can do most
things like inner joins n such. But I am now trying to do an innerjoin
within in the pubs database that comes with SQL server. I'm trying to
return the titles in the title folder based on the authors last name.
Now the only thing that gets me here is the fact that to get these
values The author has a key that relates to key in the titleauthor
table which then relates to a key to the titles table.

My question is, how do I do an inner join that goes through 3 tables
like that.

author to titleAuthor to titles,,, then display titles.


I have no problems doing innerjoins between 2 tables, but not sure
about 3. Code examples would be great. thanx.
 
J

jeff

SELECT dbo.authors.au_lname, dbo.titles.title
FROM dbo.authors INNER JOIN
dbo.titleauthor ON dbo.authors.au_id =
dbo.titleauthor.au_id INNER JOIN
dbo.titles ON dbo.titleauthor.title_id =
dbo.titles.title_id
 
T

tommaso.gastaldi

Do you mean something like: ?


SELECT
a.au_fname AS "au_fname",
a.au_lname AS "au_lname",
t1.title AS "title"
FROM
(titles t1
INNER JOIN
titleauthor t
ON t1.title_id = t.title_id)
INNER JOIN
authors a
ON a.au_id = t.au_id

or

SELECT
a.au_fname AS "au_fname",
a.au_lname AS "au_lname",
t1.title AS "title"
FROM
titles t1,
titleauthor t,
authors a
WHERE
t1.title_id = t.title_id AND
a.au_id = t.au_id


tommaso
http://cam70.sta.uniroma1.it/Community/

Bonzol ha scritto:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top