"SELECT TOP", "LEFT OUTER JOIN", "ORDER BY" gives extra rows
Posted
by Codesleuth
on Stack Overflow
See other posts from Stack Overflow
or by Codesleuth
Published on 2010-03-09T09:37:29Z
Indexed on
2010/03/09
9:51 UTC
Read the original article
Hit count: 371
I have the following Access query I'm running through OLE DB in .NET:
SELECT TOP 25
tblClient.ClientCode,
tblRegion.Region
FROM (tblClient LEFT OUTER JOIN
tblRegion ON tblClient.RegionCode = tblRegion.RegionCode)
ORDER BY tblRegion.Region
There are 431 records within tblClient
that have RegionCode
set to NULL
.
For some reason, the query above returns all these 431 records instead of the first 25.
If I change the query to ORDER BY tblClient.Client
(the name of the client) like so:
SELECT TOP 25
tblClient.ClientCode,
tblRegion.Region
FROM (tblClient LEFT OUTER JOIN
tblRegion ON tblClient.RegionCode = tblRegion.RegionCode)
ORDER BY tblClient.Client
I get the expected result set of 25 records, showing a mixture of region names and NULL
values.
Why is it that ordering by a field retrieved through a LEFT OUTER JOIN
will the TOP
clause not work?
© Stack Overflow or respective owner