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
 General SQL Server Forums
 New to SQL Server Programming
 Need Single select query

Author  Topic 

gurusamy.senthil
Yak Posting Veteran

65 Posts

Posted - 2007-02-08 : 02:44:27
Hello Everyone,

Consider the below table

DocNbr Cheques
00001 101010
00002 101010
00002 102020
00003 103030
00004 103030
00004 104040
00005 105050

I just need the single select to result the docnbr which is repeating the values. In the above case I want my result like below where the DocNbr 00002 and 00004 repeated their values.

DocNbr Cheques
00002 101010
00002 102020
00004 103030
00004 104040

Thanks in advance,

Senthil .G

Note: I do not consider if the cheque contain repeated values

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-08 : 02:48:34
[code]
select *
from yourtable t
inner join (
select DocNbr
from yourtable
group by DocNbr
having count(*) > 1
) r
on t.DocNbr = r.DocNbr
[/code]


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-08 : 02:49:04
select t1.* from table1 as t1 where t1.docnbr in (select t2.docnbr from table1 as t2 group by t2.docnbr having count(*) > 1)

select t1.*
from table1 as t1
inner join (select docnbr from table1 group by docnbr having count(*) > 1) as x on x.docnbr = t1.docnbr


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

gurusamy.senthil
Yak Posting Veteran

65 Posts

Posted - 2007-02-08 : 03:26:58
That works fine, Thank you khtan and peso.
Go to Top of Page
   

- Advertisement -