dbTalk Databases Forums  

Many-to-Many with SQL

comp.database.ms-access comp.database.ms-access


Discuss Many-to-Many with SQL in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
_DS
 
Posts: n/a

Default Many-to-Many with SQL - 02-21-2006 , 06:55 PM






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?


Reply With Quote
  #2  
Old   
Bob Quintal
 
Posts: n/a

Default Re: Many-to-Many with SQL - 02-21-2006 , 07:27 PM






_DS <_DS (AT) __nomail (DOT) com> wrote in
news:ft8nv1pob6jfeo1dk2b685voqnvjg1sclc (AT) 4ax (DOT) com:

Quote:
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.


Reply With Quote
  #3  
Old   
_DS
 
Posts: n/a

Default Re: Many-to-Many with SQL - 02-22-2006 , 07:01 PM



On Wed, 22 Feb 2006 01:27:20 GMT, Bob Quintal <rquintal (AT) sympatico (DOT) ca>
wrote:

Quote:
_DS <_DS (AT) __nomail (DOT) com> wrote in
news:ft8nv1pob6jfeo1dk2b685voqnvjg1sclc (AT) 4ax (DOT) 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.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.