B
B
beduin012020-02-07 15:12:54
Oracle
beduin01, 2020-02-07 15:12:54

How to simplify the following query?

Is it possible to somehow simplify the following query?

To prevent reselection:

WHERE 
   main_person.inn IN -- где руководитель является учредителем
   (
    select 

    grf.inn -- founders
   
    from mytablename t 
    LEFT JOIN FOUNDERS grf ON grf.record_id = t.grn_record_id
    LEFT JOIN MAIN_PERSONS grmp ON grmp.record_id = t.grn_record_id 
    WHERE t.inn = '7714728670' 
   
   )
   
   AND 
   
   main_person.inn IN -- где руководитель является руководителем
   (
    select 

    grmp.inn
   
    from mytablename t 
    LEFT JOIN FOUNDERS grf ON grf.record_id = t.grn_record_id
    LEFT JOIN MAIN_PERSONS grmp ON grmp.record_id = t.grn_record_id    
    WHERE t.inn = '7714728670' 
   
   )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
igaraev, 2020-02-13
@igaraev

WHERE
exists
(
select 'x'
from mytablename t
LEFT JOIN FOUNDERS grf ON grf.record_id = t.grn_record_id
LEFT JOIN MAIN_PERSONS grmp ON grmp.record_id = t.grn_record_id
WHERE t.inn = '7714728670'
and (main_person.inn=grf. inn or main_person.inn=grmp.inn)
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question