SQL Help

T

Tom Nowak

I have an ASP.NET Web application that I want to write a query or stored
procedure for.

I want to get the results from two tables. One result set will contain all
the names in one table. The second result set will contain some names from a
second table. Then, I want to display the names that are in the first table
that are NOT in the second table.

Any suggestions would be appreciated.
 
T

Tom Nowak

Thank you so much for your help! Your suggestion worked immediately!

I have written a Stored Procedure to generate results in one temporary
table, then generated results in another temporary table, and I couldn't
figure out how to only display rows that were in one and not the other. I
have spent hours trying to figure it out!

Thanks again!
 
P

Paul Shapiro

The other way to write the same query is with an Exists clause. I prefer
this because the intention seems clearer when I read it, but the results are
identical and with most database servers performance should also be the
same. With some servers one or the other may give better performance, but
the only way to know would be to test both approaches.

Select A.fieldOne, A.fieldTwo, etc.
From TableA as A
Where Not Exists (Select * From TableB as B Where B.key=A.key)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top