Efficient way to move tuples from one table to another, discarding repetitions of a specific attribute

0

I have two tables, and I have to move data from one to the other. The first table stores, among other things, customer data. The second table is empty, it is where I want to insert the tuples.

The first table has this form, I do not write it completely in oracle, I just want to give a vision of what it has.

TABLE CLIENTES{
ID_CLIENTE (primary key)
NOMBRE
APELLIDO1
APELLIDO2
EMAIL(unique)
.
.
.
}

The second table has, among other things, all the attributes of clients, and they are the ones that I have to insert clients. The problem is that I do not have to do one:

INSERTAR EN clientes
SELECCIONAR  clientid,name,apellido1, apellido2, email, (...)
FROM (tabla_2);

The previous code is obviously not syntactically correct, it is a sample of how I do the query. With the above I get a unique(USER.PK_CLIENTES) constraint violated because in table 2 there are repeated ids.

What have I been up to now?

I have located how many repeat clients there are in table 2 using the COUNT('X')>1 but I just do not get the syntax of how to get tuples, say the client 1, and if another tuple is found with client 1 do not target it in clients. I've tried with groups by, min, but I just did not get it right because I do not put it in the right order or something ...

EXAMPLE OF CONTENT IN TABLE 2:

idcliente nombre apell1 apell2 email ... ... peliculas_vistas puntuación

10002     Pedro  Pérez  Pérez  perez@ .. ... avatar           10
10002     Pedro  Pérez  Pérez  perez@ .. ... el rey leon      9
10003     Edu    Rey    Ramos  ramos@ .. ... el rey león      8.5

RESULTS DESIRED IN CLIENTS TABLE:

id_cliente nombre apellido1 apellido2 email

10002      Pedro  Pérez     Pérez     perez@
10003      Edu    Rey       Ramos     ramos@

I can not put intermediate tables, I have to work with these two only. Basically it is to take the parameters that customers need from table 2, but NOT to take those tuples whose client already we have introduced them in clients. I hope you have explained to me.

    
asked by Keka Bron 06.03.2017 в 17:43
source

1 answer

0

It is already solved, you only had to minimize clients, and then a group by clienteid, it was me that put the syntax wrong

    
answered by 06.03.2017 / 19:01
source