Amazon Ad

Thursday, 29 August 2013

How to get duplicate values from table in MS SQL Server

Here are some of the t-Sql queries you can use to find duplicate values

1. Using group by and having

select CabTransactions.TransactionId,y.cabid,y.orderid from
(
select min(cabid) as cabid,orderid,action from CabTransactions
group by cabid,orderid,action
having count(transactionid)>1
) as y,CabTransactions where y.cabid=CabTransactions.CabId and y.OrderId=CabTransactions.OrderId

2. Using not in

select * from cabtransactions where transactionid not in
(
    select min(transactionid) from cabtransactions group by cabid,orderid
)

Thanks
Ritesh

No comments:

Post a Comment

Comments are welcome, Please join me on my Linked In account

http://in.linkedin.com/pub/ritesh-tandon/21/644/33b

How to implement Captcha v3 in ASP.NET

 I was facing an issue of dom parsing in my website. I finally resolved it by using Google Captcha V3. Step 1: Get your keys from https:...