How to show the repeated elements of a table in Oracle

0

Friends I have the following table called Scheduling_delivery with the following fields

cod_entrega, cod_ordenamiento, cod_centro_atencion, cod_medicamento

I need to find when there is only duplicate data on the medication. for example

entrega 1, ordenamiento 1289, centroAtencion 12345, cod_medicamento 5
entrega 1, ordenamiento 1289, centroAtencion 12345, cod_medicamento 6

Usually they are like that, where the medication is different, but I need to locate only those that have the same order.

I'm trying to do it like that

SELECT ENTRE.COD_ORDENAMIENTO, ENTRE.COD_CENTRO_ATENCION, ENTRE.COD_ENTREGA, ENTRE.COD_MEDICAMENTO,
       ENTRE2.COD_ORDENAMIENTO, ENTRE2.COD_CENTRO_ATENCION, ENTRE2.COD_ENTREGA, ENTRE2.COD_MEDICAMENTO
FROM IPS_PROGRAMACION_ENTREGAS@CONSUBAS ENTRE,
     IPS_PROGRAMACION_ENTREGAS@CONSUBAS ENTRE2
WHERE ENTRE.COD_ORDENAMIENTO = ENTRE2.COD_ORDENAMIENTO AND
 ENTRE.COD_CENTRO_ATENCION = ENTRE2.COD_CENTRO_ATENCION
AND ENTRE.COD_ENTREGA = ENTRE2.COD_ENTREGA
AND ENTRE.COD_MEDICAMENTO = ENTRE2.COD_MEDICAMENTO;

But it brings me only the repeated data from the same query.

    
asked by Paul Valencia 24.09.2017 в 23:41
source

1 answer

0

I will only give you an idea, because I do not understand well which are the columns to which you want to have the repeated rows. look, without doing JOIN with the same table you can find rows with more than one repetition in the following way:

SELECT COD_ORDENAMIENTO, COD_CENTRO_ATENCION, COD_ENTREGA, COD_MEDICAMENTO
FROM IPS_PROGRAMACION_ENTREGAS@CONSUBAS
GROUP BY COD_ORDENAMIENTO, COD_CENTRO_ATENCION, COD_ENTREGA, COD_MEDICAMENTO
HAVING COUNT(*) > 1 ;

If the repeated columns are the first three you can remove COD_MEDICAMENTO.

    
answered by 10.01.2018 в 18:25