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)
 Query repeated valus in one table

Author  Topic 

csu
Starting Member

2 Posts

Posted - 2010-07-16 : 17:59:01
Table A has the following records:
No Desc.
1 , A
1 , B
1 , C
2 , A
2 , B
3 , A
3 , C

I need to get the following:

2

(only the No that don't have C under the desc.)

Thanks for any suggested query

singularity
Posting Yak Master

153 Posts

Posted - 2010-07-16 : 19:23:40
select distinct no
from yourtable a
where not exists (select * from yourtable b where b.desc = 'C' and a.no = b.no)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-19 : 07:20:59
or

select no from table
group by no
having sum(case when desc='c' then 1 else 0 end)=0


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

csu
Starting Member

2 Posts

Posted - 2010-07-19 : 09:28:27
Thanks, that did the job for me.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-19 : 10:13:21
quote:
Originally posted by csu

Thanks, that did the job for me.


No problem

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -