473,320 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Many-to-Many with SQL

_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
3 5245
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
_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
_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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: a | last post by:
Hey, I am building a Database App using VB.NET instead of MSAccess. I need some tips for the data access strategy. I like the 'Microsoft Application Blocks for .NET' approach, but am curious...
0
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.8.0b1 release of SQLObject. This is the first beta of the new branch. Taking into account that it is a result of rather large job the beta period will be...
0
by: rengaraj | last post by:
Hello. I have an @Entity class, Person, with a @ManyToMany relation with itself. This relation is the friend association. The code of the class is as follows: @Entity @Table(name = "PERSON",...
0
by: Oleg Broytmann | last post by:
Hello! I'm pleased to announce the 0.8.0 release of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.