Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

duplicate value

Posted on 2015-01-20
16
Medium Priority
?
51 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 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
 
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 77

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 77

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 23

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

715 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