Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 this should be easy...can't think right now

Author  Topic 

SQL_Rookie
Starting Member

32 Posts

Posted - 2009-09-23 : 16:29:56
I got a simple query that I can not figure out right now...

table looks like this

column text column number
ABC 123
ABC 123
ABC 123
DEF 145
DEF 148
DEF 123
XYZ 345


I want the query to return rows that have the same column number for every row that has the same column text...
in the above example I only would want to return
ABC and the XYZ rows....the DEF have different column numbers.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-23 : 16:36:38
maybe this:

select [column text]
,min([column number]) as [column number]
from [table]
group by [column text]
having count(distinct [column number]) = 1

EDIT:
--this would work too:
having min([column number]) = max([column number])


Be One with the Optimizer
TG
Go to Top of Page

SQL_Rookie
Starting Member

32 Posts

Posted - 2009-09-23 : 16:47:32
thanks....I could not think how I could do the group by but only return the ones that had the same column number....that min or the min = max does it..
Go to Top of Page
   

- Advertisement -