Solved

oracle eliminate duplicate records

Posted on 2011-02-16
3
602 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 35

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

920 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

15 Experts available now in Live!

Get 1:1 Help Now