Solved

oracle eliminate duplicate records

Posted on 2011-02-16
3
613 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
[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 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

615 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