Link to home
Start Free TrialLog in
Avatar of chalie001
chalie001

asked on

duplicate value

hi how can i get duplicate value in this sql

select obj_name from cal_obj
Avatar of Naveen Kumar
Naveen Kumar
Flag of India image

sorry, u want duplicate values ?
what is cal_obj contain ?if it has duplicate values for this column in your table records, then it will display right otherwise not.
Avatar of chalie001
chalie001

ASKER

i what to get duplicate value and than delete tham
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Slightwv
For Pointing me on Deleting Duplicate Records

Please Try This
SELECT FieldName, COUNT(*) TotalCount
  FROM [YourDB].[dbo].[YourTable]
GROUP BY FieldName
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC
GO

Open in new window



Then Use Following  To Delete ALL DUPLICATE RECORDS

WITH SimpleDLTE 
AS 
(
      SELECT ROW_NUMBER () OVER ( PARTITION BY YourField ORDER BY YourField) AS RNUM 
       FROM [YourDB].[dbo].[YourTable]
)

DELETE FROM SimpleDLTE WHERE RNUM > 1
GO

/* Your Details without Duplicates */
SELECT *   FROM [YourDB].[dbo].[YourTable]
GO

Open in new window

For Oracle
Try This

DELETE FROM YourTableOwner.YourTabel WHERE rowid not in (SELECT MIN(rowid) FROM YourTableOwner.YourTabel GROUP BY YourField)

Open in new window

>>For Oracle  Try This

Isn't that pretty much the same thing I posted in http:#a40559578

The only difference is 'not in' versus '>' and mine is a correlated subquery.
Try

delete from cal_obj where rowid in (
select rowid from (
select rowid,obj_name,
row_number () over (partition by obj_name order by rowid) as rid
from cal_obj) where rid <> 1);

Open in new window

crystal_Tech,

That is the worst one yet.

I agree that there are many ways to solve this problem.  There is no need to post them ALL.  I'm sure I could come up with a few more that are even worse performing that your latest one but why?

If there are indexes involved, and there probably are, the correlated subquery that I posted is very likely the most efficient.
thanks
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.