HighTechTalks DotNet Forums  

How to GROUP SELECT WITH some value and WITHOUT some other?

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss How to GROUP SELECT WITH some value and WITHOUT some other? in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Lloyd Dupont
 
Posts: n/a

Default How to GROUP SELECT WITH some value and WITHOUT some other? - 11-04-2007 , 08:17 AM






I have a table

Customer
===========
INT (Identity), Varchar(50), Varchar(50), Varchar(50)
============
ID, City, FirstName, LastName
=================
1 Brisbane Jon Smith
2 Brisbane Allan Parker
3 Sydney James Parker

And now I try to find
all City
WITH customer named 'Paker'
AND WITHOUT customer named 'Smith'
(That would be 'Sydney' in this sample).

What kind of SQL could I write to do that?


some kind of SQL like below would be good if it could work
SELECT City
FROM Customer
WHERE LastName NOT IN ('Smith') and LastName in ('Parker')
GROUP BY City



Reply With Quote
  #2  
Old   
Lloyd Dupont
 
Posts: n/a

Default Re: How to GROUP SELECT WITH some value and WITHOUT some other? - 11-04-2007 , 08:23 AM






I found it!!

==============
SELECT City
FROM Customer
WHERE LastName IN ('Parker')
AND City NOT IN (
SELECT City
FROM Customer
WHERE LastName IN ('Smith')
GROUP BY City )
GROUP BY City;

==============


"Lloyd Dupont" <net.galador@ld> wrote

Quote:
I have a table

Customer
===========
INT (Identity), Varchar(50), Varchar(50), Varchar(50)
============
ID, City, FirstName, LastName
=================
1 Brisbane Jon Smith
2 Brisbane Allan Parker
3 Sydney James Parker

And now I try to find
all City
WITH customer named 'Paker'
AND WITHOUT customer named 'Smith'
(That would be 'Sydney' in this sample).

What kind of SQL could I write to do that?


some kind of SQL like below would be good if it could work
SELECT City
FROM Customer
WHERE LastName NOT IN ('Smith') and LastName in ('Parker')
GROUP BY City




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.