views:

55

answers:

3
SELECT DISTINCT bw.Bor_name
FROM Borrower AS bw, Loan AS l
JOIN Book_Copy AS bc
ON l.Bc_id = bc.Bc_id
WHERE bw.Bor_id = l.Bor_id
GROUP BY l.Bor_id, bc.Bt_id
HAVING COUNT( bc.Bt_id ) > 1
AND COUNT( l.Bor_id ) > 1;

This works perfectly in a MySQL testing environment but won't work in MS Access 2007 where I actually need it run. I have a few other queries which involve using JOIN and it gives the same error for them as well: "Syntax error in FROM clause".

Edit:

SELECT DISTINCT l.Bor_id
FROM Loan AS l
INNER JOIN Book_Copy AS bc
ON l.Bc_id = bc.Bc_id
GROUP BY l.Bor_id, bc.Bt_id
HAVING COUNT( bc.Bt_id ) > 1
AND COUNT( l.Bor_id ) > 1

Actually this one works fine and gives me the required id number, but what I want to output is the name which is contained in the Borrower table.

A: 

I think you cannot mix implicit and explicit join. you should try with this

SELECT DISTINCT bw.Bor_name
FROM Borrower AS bw
join Loan AS l
on bw.Bor_id = l.Bor_id
JOIN Book_Copy AS bc
ON l.Bc_id = bc.Bc_id
GROUP BY l.Bor_id, bc.Bt_id
HAVING COUNT( bc.Bt_id ) > 1
AND COUNT( l.Bor_id ) > 1;
il_guru
You can mix implicit/explicit JOINs in Jet/ACE/Access SQL. The problem is hte lack of JOIN type, INNER/LEFT/RIGHT.
David-W-Fenton
@il_guru, just to confirm - it works perfectly in MySQL. I'll test again in Access and let you know what the result was.
Hristo
There shouldn't be any problem mixing implicit and explicit JOINs in Access, either, as long as the proper JOIN syntax is used.
David-W-Fenton
Unfortunately, the code suggested above does not work in MS Access either. It still gives me the same annoying error.
Hristo
Unsing INNER/LEFT/RIGHT does not help either.
Hristo
+3  A: 

I didn't test with Access 2007. However Access 2003 complains about "syntax error in from clause" if I try JOIN alone (without explicitly using INNER JOIN). Seems the database engine requires you designate the JOIN as either RIGHT JOIN, LEFT JOIN, or INNER JOIN; I can't find any other variation it will accept.

Update: I will suggest you create a new query with Access' query designer. Just add the tables and set up the joins. (Leave the GROUP BY and everything else for later.) Then you can switch to SQL View to see the type of join syntax which makes Access happy.

HansUp
Thanks very much for the response here too! Yes, that's what I have tried so far, but with no success.
Hristo
A: 
SELECT DISTINCT bw.Bor_name
FROM Borrower AS bw, Loan AS l
JOIN Book_Copy AS bc
ON (l.Bc_id = bc.Bc_id)
WHERE bw.Bor_id = l.Bor_id
GROUP BY bw.Bor_name, bc.Bt_id
HAVING COUNT( bc.Bt_id ) > 1
AND COUNT( l.Bor_id ) > 1;

Eventually this one did the job. Thanks once again to all who contributed with advice!

Hristo