1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Rewriting query

Discussion in 'SQL PL/SQL' started by pts641, May 20, 2013.

  1. pts641

    pts641 Guest

    I need help in rewriting this query. I need alternative ways which can achieve the same result.

    select count(T1."D_ID")
    from "TABLE1" T1
    where (exists
    (select T2."DP_ID"
    from "TABLE2" T2
    where T2."D_ID"=T1."D_ID"
    and (T2."RR_ID" in (392 , 394))
    and (T2."P_ID" in
    (select max(T3."P_ID")
    from "TABLE3" T3
    where T3."EP_ID"='494'))))
    and (exists
    (select T4."M_ID"
    from "TABLE4" T4
    inner join "TABLE5" T5
    on T4."PR_ID"=T5."PR_ID"
    where (T4."MSR_ID" in (2, 21 , 1128 ))
    and T5."CM_ID"=T4."M_ID"
    and (T5."PRSR_ID" is null
    or T5."PRSR_ID"=3128)
    and T5."S_ID"=
    (select min(T6."S_ID")
    from "TABLE6" T6
    where T6."D_ID"=T1_."D_ID"))));
  2. zargon

    zargon Community Moderator Forum Guru

    Likes Received:
    Trophy Points:
    Aurora, CO
    It would be nice to have table definitions and sample data as well as this query -- it's difficult to re-write a query successfully without tables to query and data to return.