By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,490 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,490 IT Pros & Developers. It's quick & easy.

Many-to-Many with SQL

P: n/a
_DS
I'm not sure if there is a difference in syntax for Access's SQL
commands. I'm having trouble with what should be a very simple
compound join statement.

An example: 'Authors' table has a field called AuthorID. A 'Books'
table has a field called BookID. Since an author can write more than
one book, and a book can be written by multiple authors, this calls
for a link table ("bridge table" "association table" whatever). Call
that table 'AuthorsBooks.' It has only two fields, AuthorID and
BookID, which match the other id fields.

Robert Veiera's book on SQL (not on Access per se) spells out a query
for exactly the operation above. Similar to:
Select Authors.AuthorName, Books.BookTitle
FROM Authors
INNER JOIN AuthorsBooks ON Authors.AuthorID = AuthorsBooks.AuthorID
INNER JOIN Books ON AuthorsBooks.BookID = Books.BookID

Veiera's code is similar but again, written in SQL Server's dialect.
I'm presuming that Access is looking for slightly different syntax.
Access's error message only narrows it to the 'FROM' statement.
Ideas?

Feb 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
i threw together the tables you described, and write the query to match the
SQL you posted. it worked for me; the only difference in the statement was
the automatic placement of parentheses (i built the query in the design
grid) by Access:

SELECT Authors.AuthorName, Books.BookTitle
FROM (Authors INNER JOIN AuthorsBooks ON Authors.AuthorID =
AuthorsBooks.AuthorID) INNER JOIN Books ON AuthorsBooks.BookID =
Books.BookID

hth
"_DS" <_DS@__nomail.com> wrote in message
news:ft********************************@4ax.com...
I'm not sure if there is a difference in syntax for Access's SQL
commands. I'm having trouble with what should be a very simple
compound join statement.

An example: 'Authors' table has a field called AuthorID. A 'Books'
table has a field called BookID. Since an author can write more than
one book, and a book can be written by multiple authors, this calls
for a link table ("bridge table" "association table" whatever). Call
that table 'AuthorsBooks.' It has only two fields, AuthorID and
BookID, which match the other id fields.

Robert Veiera's book on SQL (not on Access per se) spells out a query
for exactly the operation above. Similar to:
Select Authors.AuthorName, Books.BookTitle
FROM Authors
INNER JOIN AuthorsBooks ON Authors.AuthorID = AuthorsBooks.AuthorID
INNER JOIN Books ON AuthorsBooks.BookID = Books.BookID

Veiera's code is similar but again, written in SQL Server's dialect.
I'm presuming that Access is looking for slightly different syntax.
Access's error message only narrows it to the 'FROM' statement.
Ideas?

Feb 22 '06 #2

P: n/a
_DS <_DS@__nomail.com> wrote in
news:ft********************************@4ax.com:
I'm not sure if there is a difference in syntax for Access's
SQL commands. I'm having trouble with what should be a very
simple compound join statement.

An example: 'Authors' table has a field called AuthorID. A
'Books' table has a field called BookID. Since an author can
write more than one book, and a book can be written by
multiple authors, this calls for a link table ("bridge table"
"association table" whatever). Call that table
'AuthorsBooks.' It has only two fields, AuthorID and BookID,
which match the other id fields.

Robert Veiera's book on SQL (not on Access per se) spells out
a query for exactly the operation above. Similar to:
Select Authors.AuthorName, Books.BookTitle
FROM Authors
INNER JOIN AuthorsBooks ON Authors.AuthorID =
AuthorsBooks.AuthorID INNER JOIN Books ON
AuthorsBooks.BookID = Books.BookID

Veiera's code is similar but again, written in SQL Server's
dialect. I'm presuming that Access is looking for slightly
different syntax. Access's error message only narrows it to
the 'FROM' statement. Ideas?

SELECT authors.authorname, books.booktitle
FROM (
authors
INNER JOIN authorsbooks ON authors.authorid =
authorbook.authorid
)
INNER JOIN books ON authorbook.bookid = books.bookid;

Access insists on the parentheses.

--
Bob Quintal

PA is y I've altered my email address.
Feb 22 '06 #3

P: n/a
_DS
On Wed, 22 Feb 2006 01:27:20 GMT, Bob Quintal <rq******@sympatico.ca>
wrote:
_DS <_DS@__nomail.com> wrote in
news:ft********************************@4ax.com :
I'm not sure if there is a difference in syntax for Access's
SQL commands. I'm having trouble with what should be a very
simple compound join statement.
SELECT authors.authorname, books.booktitle
FROM (
authors
INNER JOIN authorsbooks ON authors.authorid =
authorbook.authorid
)
INNER JOIN books ON authorbook.bookid = books.bookid;

Access insists on the parentheses.


Tina and Bob: I hadn't seen any mention of parens in the SQL books I
own, so I presume it is an Access peculiarity. Thanks for the
followup.

Feb 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.