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
 duplicate query

Author  Topic 

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-02-11 : 08:30:51
hi team , i have a table in my database like :

id vid amt remarks
1 111 50 a
2 111 50 c
3 111 60 ss
4 112 40 dd
5 112 40 cc
6 112 80 dd
7 112 90 dd

then i need to get records from this table that only rows from table is
get selected where vid and amt col values are same.

challenge everything

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-11 : 08:34:37
you mean this?

SELECT columns...
FROM
(
SELECT *,COUNT(1) OVER (PARTITION BY vid,amt) AS Cnt
FROM table
)t
WHERE Cnt >1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-02-11 : 09:20:06
yes exactly , thanks a lot

challenge everything
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-11 : 09:21:16
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-11 : 09:25:07
SELECT Vid, amt
FROM table
GROUP BY Vid, amt
HAVING COUNT(*) > 1

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -