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

x
?
Solved

oracle eliminate duplicate records

Posted on 2011-02-16
3
Medium Priority
?
618 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 200 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 1800 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

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