Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

single-row subquery returns more than one row - how to find the duplicate?

iam not a big ORACLE - SQL Expert, so i hope someone knows a good way to find the "duplicate" record wich is causing the: single-row subquery returns more than one row error.

This my Statement:

    SELECT
    CAST(af.SAP_SID AS VARCHAR2(4000)) APP_ID,
    (SELECT DR_OPTION
       FROM
          DR_OPTIONS 
       WHERE DR_OPTIONS.ID = (
            select dr_option from applications where applications.sap_sid = af.sap_sid)) DR_OPTION
FROM
    APPLICATIONS_FILER_VIEW af

it works on my test system, so iam "sure" there must be an error inside the available data records, but i have no idea how to find those ..

like image 239
opHASnoNAME Avatar asked Feb 21 '23 17:02

opHASnoNAME


1 Answers

Try with this query:

select applications.sap_sid, count(dr_option) 
from applications 
group by applications.sap_sid 
having count(dr_option) > 1

This should give you the sap_sid of the duplicated rows

like image 157
A.B.Cade Avatar answered Feb 23 '23 05:02

A.B.Cade