Solved

duplicate value

Posted on 2015-01-20
16
46 Views
Last Modified: 2015-06-23
hi how can i get duplicate value in this sql

select obj_name from cal_obj
0
Comment
Question by:chalie001
  • 3
  • 3
  • 2
  • +2
16 Comments
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 40559216
sorry, u want duplicate values ?
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 40559217
what is cal_obj contain ?if it has duplicate values for this column in your table records, then it will display right otherwise not.
0
 

Author Comment

by:chalie001
ID: 40559435
i what to get duplicate value and than delete tham
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40559578
Try this:

delete from cal_obj a where rowid> (select min(rowid) from cal_obj b where  a.obj_name=b.obj_name);
0
 
LVL 1

Expert Comment

by:crystal_Tech
ID: 40562099
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

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Expert Comment

by:crystal_Tech
ID: 40562963
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

0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40562966
>>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.
0
 
LVL 1

Expert Comment

by:crystal_Tech
ID: 40563104
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

0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40563254
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.
0
 

Author Comment

by:chalie001
ID: 40578172
thanks
0
 
LVL 22

Expert Comment

by:Steve Wales
ID: 40845989
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now