Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

paradoxical query results?
Hi -

I am getting perplexing, seemingly inconsistent results from two simple
queries, and I was wondering if I'm doing something obviously
brainless.

The first query is:

select colX, colY from
(select distinct colX from tblX) x full outer join
(select distinct colY from tblY) y
on x.colX=y.colY
order by y.colY

This query returns 28109 rows, the first 38 of which are NULL in colY,
but NOT NULL in colX. The second query is:

select colX from tblX where colX not in (select colY from tblY)

This query returns nothing, and that's the problem. Shouldn't this
query return the 38 values that are in colX but not colY? Shouldn't the
subquery return the list of values in colY, which as the first query
demonstrates, is lacking exactly 38 values that appear in colX?

Thanks for any help.


Report this thread to moderator Post Follow-up to this message
Old Post
jbm05
04-25-05 06:23 PM


Re: paradoxical query results?
I'm guessing that you have NULLs in ColY. In that case the NOT IN
expression will always evaluate UNKNOWN. Try:

SELECT colX
FROM tblX
WHERE colX NOT IN
(SELECT colY
FROM tblY
WHERE colY IS NOT NULL)

or use NOT EXISTS:

SELECT colX
FROM tblX
WHERE NOT EXISTS
(SELECT *
FROM tblY
WHERE colY = tblX.colX)

--
David Portas
SQL Server MVP
--


Report this thread to moderator Post Follow-up to this message
Old Post
David Portas
04-25-05 06:23 PM


Re: paradoxical query results?
I was completely unaware of that behavior; adding the where condition
to the subquery solved the problem. Thank you very much.


Report this thread to moderator Post Follow-up to this message
Old Post
jbm05
04-25-05 06:23 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 10:29 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006