Solved

oracle eliminate duplicate records

Posted on 2011-02-16
3
601 Views
Last Modified: 2012-05-11
The result of this query must be stored in another table
select      distinct
            CodUnico,
            RazonSocial,
            NumeroDocumento,
            CodTipoBanca,
            CodGrupo,
            CodCalificacionSBS,
            CodFeve,
            Rating,
            CodSegmentacion,
            CodEjecutivoNegocios,
            DesEjecutivoNegocios,
            LineaCredTienda
from tmp_Solicitud

 but I have a problem.
 The table where I insert the data is CodUnico primary key. Although I put in my query word is being shown distinct repeated CodUnico
 (see picture), how I can fix this??

repeatedROW01.jpg
repeatedROW02.jpg
0
Comment
Question by:enrique_aeo
3 Comments
 
LVL 9

Assisted Solution

by:AriMc
AriMc earned 50 total points
ID: 34909396
The DISTINCT keyword applies to all the columns in your select statement, ie. all rows having distinct set of all values are returned. You need to decide some other criteria to select only one row per CodUnico.

0
 

Author Comment

by:enrique_aeo
ID: 34909484
i can not
i attched the file
clientes.csv
0
 
LVL 34

Accepted Solution

by:
Mark Geerlings earned 450 total points
ID: 34909503
Be careful with using that word "distinct" in Oracle queries!  There are two significant problems with it:
1. That always forces Oracle to do a sort, and depending on the number of rows returned, that can add a huge performance penalty.
2. Oracle's understanding of what "distinct" means does not always agree with what humans expect.  There are two reasons for this.  First, Oracle understands "distinct" to apply to the combination of *ALL* columns being returned (not just to the first column).  Second, if you have a date field being returned, date values in Oracle can include the time-of-day.  Depending on your settings for NLS_DATE_FORMAT, you may or may not see the time portion, so Oracle may return rows that appear to be duplicates, but in fact have a different time-of-day.

You will need to do a sub-query to first select the distinct CodUnico values but this can better be done in Oracle by using a group operator (min, max, etc.) than by actually using "distinct", then get the other values for those rows, something like this:

select      CodUnico,
            RazonSocial,
            NumeroDocumento,
            CodTipoBanca,
            CodGrupo,
            CodCalificacionSBS,
            CodFeve,
            Rating,
            CodSegmentacion,
            CodEjecutivoNegocios,
            DesEjecutivoNegocios,
            LineaCredTienda
from tmp_Solicitud ts
where (ts.CodUnico, ts.rowid) in
(select t.CodUnico, min(t.rowid) from tmp_Solicitud t
 group by t.CodUnico);
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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

758 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

21 Experts available now in Live!

Get 1:1 Help Now