D
David Carr
Hi there,
I have been plagued with problems over the years when trying to get the
parentheses right for the following:
Table A:
A_ID - PK
A_Name
B_ID - Relationship to B.B_ID
with n records, some of which where B_ID is a NULL.
Table B:
B_ID - PK
MyFilterValue - Some value to filter on.
So my goal is to get all the records in table A, LEFT JOIN to the records in
table B providing they meet the filter criteria. Ignoring parentheses, I
typically do this by:
SELECT *
FROM A LEFT JOIN B ON A.B_ID = B.B_ID AND B.MyFilterValue = @SomeValue
The problem is that MS Access 2003 often balks at this. Eventually with
some tweaking of parentheses it ends up working. Unfortunately, the Query
Builder in VB.NET 2005 also balks and cannot be convinced to work otherwise.
If anyone can offer up general SQL performance/best practices advice on how
to achieve the goal, and/or how to resolve this in Access/VB.NET Query
Builder, that would be most appreciated.
Thanks in advance,
David
PS: I realise that another approach can be to use a subquery, such as:
SELECT *
FROM A LEFT JOIN (SELECT * FROM B WHERE B.MyFilterValue = @SomeValue) AS B_1
ON A.B_ID = B_1.B_ID
where Access seems to be less finicky with subqueries than dealing the top
statement and its parentheses. Aside from the reading something about
subqueries not being as effecient, regardless the VB.NET/JET provider still
chokes.
I have been plagued with problems over the years when trying to get the
parentheses right for the following:
Table A:
A_ID - PK
A_Name
B_ID - Relationship to B.B_ID
with n records, some of which where B_ID is a NULL.
Table B:
B_ID - PK
MyFilterValue - Some value to filter on.
So my goal is to get all the records in table A, LEFT JOIN to the records in
table B providing they meet the filter criteria. Ignoring parentheses, I
typically do this by:
SELECT *
FROM A LEFT JOIN B ON A.B_ID = B.B_ID AND B.MyFilterValue = @SomeValue
The problem is that MS Access 2003 often balks at this. Eventually with
some tweaking of parentheses it ends up working. Unfortunately, the Query
Builder in VB.NET 2005 also balks and cannot be convinced to work otherwise.
If anyone can offer up general SQL performance/best practices advice on how
to achieve the goal, and/or how to resolve this in Access/VB.NET Query
Builder, that would be most appreciated.
Thanks in advance,
David
PS: I realise that another approach can be to use a subquery, such as:
SELECT *
FROM A LEFT JOIN (SELECT * FROM B WHERE B.MyFilterValue = @SomeValue) AS B_1
ON A.B_ID = B_1.B_ID
where Access seems to be less finicky with subqueries than dealing the top
statement and its parentheses. Aside from the reading something about
subqueries not being as effecient, regardless the VB.NET/JET provider still
chokes.