Main Page | Report Page

 

  .NET DotNet Forum Index » ASP.NET Forum » SQL Help...

Author Message
Tom Nowak...
Posted: Tue Apr 07, 2009 12:14 pm
 
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.
 
Patrice...
Posted: Tue Apr 07, 2009 12:39 pm
 
My personal preference is to use a LEFT JOIN :

SELECT *
-- Base table
FROM a
-- Match table b on key and get NULL values if no match
LEFT JOIN b ON b.Key=a.Key
-- Where we don't have a match
WHERE b.Key IS NULL

See also :
http://msdn.microsoft.com/en-us/library/ms191472.aspx (you'll learn about
joins)
http://msdn.microsoft.com/en-us/library/ms175838.aspx (you'll learn about
other possible options such as EXISTS etc...)

--
Patrice


"Tom Nowak" <TomNowak at (no spam) discussions.microsoft.com> a écrit dans le message de
groupe de discussion : D26250CA-609D-43FA-A175-43BFBD4A9B0C at (no spam) microsoft.com...
Quote:
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.

 
Tom Nowak...
Posted: Tue Apr 07, 2009 1:35 pm
 
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!

"Patrice" wrote:

Quote:
My personal preference is to use a LEFT JOIN :

SELECT *
-- Base table
FROM a
-- Match table b on key and get NULL values if no match
LEFT JOIN b ON b.Key=a.Key
-- Where we don't have a match
WHERE b.Key IS NULL

See also :
http://msdn.microsoft.com/en-us/library/ms191472.aspx (you'll learn about
joins)
http://msdn.microsoft.com/en-us/library/ms175838.aspx (you'll learn about
other possible options such as EXISTS etc...)

--
Patrice


"Tom Nowak" <TomNowak at (no spam) discussions.microsoft.com> a crit dans le message de
groupe de discussion : D26250CA-609D-43FA-A175-43BFBD4A9B0C at (no spam) microsoft.com...
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.


 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Fri Jul 01, 2016 12:09 pm