Solved

oracle eliminate duplicate records

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - CSV to Oracle table 4 67
SQL Retrieve Values 4 68
case statement in where clause 5 48
Can anyone please tell me what does below Stored Procedure does? 4 29
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
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…
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…
This video shows how to recover a database from a user managed backup

776 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