
February 22nd, 2006, 01:05 AM
| | | Many-to-Many with SQL
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? |

February 22nd, 2006, 01:45 AM
| | | Re: Many-to-Many with SQL
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:ft8nv1pob6jfeo1dk2b685voqnvjg1sclc@4ax.com...[color=blue]
> 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?
>[/color] | 
February 22nd, 2006, 01:55 AM
| | | Re: Many-to-Many with SQL
_DS <_DS@__nomail.com> wrote in
news:ft8nv1pob6jfeo1dk2b685voqnvjg1sclc@4ax.com:
[color=blue]
> 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?
>[/color]
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. | 
February 23rd, 2006, 01:15 AM
| | | Re: Many-to-Many with SQL
On Wed, 22 Feb 2006 01:27:20 GMT, Bob Quintal <rquintal@sympatico.ca>
wrote:
[color=blue]
>_DS <_DS@__nomail.com> wrote in
>news:ft8nv1pob6jfeo1dk2b685voqnvjg1sclc@4ax.com :
>[color=green]
>> 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.[/color][/color]
[color=blue]
>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.[/color]
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. | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 205,414 network members.
|