ACC2000: Outer Join with WHERE Clause Returns Unexpected Records (208880)
The information in this article applies to:
This article was previously published under Q208880 Moderate: Requires basic macro, coding, and interoperability skills.
This article applies only to a Microsoft Access database (.mdb).
SYMPTOMS
When you run a query based on two tables (in this example, table A
and table B) with an outer join to include all the records from table A,
and you apply a WHERE clause to table B, you expect to see all the records from table A and those records from table B that satisfy the WHERE clause. Instead, only those records from table B that satisfy the WHERE clause and have a matching value in table A are returned.
CAUSE
When you run the query, the outer join is performed first, creating all the
records from table A. Then, the WHERE clause from table B is applied to all
the records, eliminating records from the query. The result set does not
contain all the records from table A, but contains only those for which the
condition is met for table B.
Unlike Microsoft Access, SQL Server currently processes the WHERE before
the join. This is because this feature was implemented before the ANSI
SQL-92 standard. Before then, there was no outer join spec at all.
Therefore, the same query can return different results against SQL
Server, depending on whether you use a Select query or a SQL pass-through
query (in which case SQL Server handles the query and simply returns
the results.)
RESOLUTION
If you want to return all the records in table A, you can use two queries.
The first query should apply the WHERE clause to table B, and the second
query should combine table A with the first query to perform the outer
join.
STATUS
This type of query processing complies with the ANSI SQL 92 specification.
REFERENCESFor more information about relationships, click Microsoft Access Help on the
Help menu, type work with relationships in the Office Assistant or
the Answer Wizard, and then click Search to view the topics
returned.
Modification Type: | Minor | Last Reviewed: | 7/15/2004 |
---|
Keywords: | kbprb KB208880 |
---|
|