postgresql - More Efficient Way to Join Three Tables Together in Postgres -


i attempting link 3 tables in postgres.

3 tables generated subqueries. first table linked second table variable call_sign full join (because want superset of entries both tables). third table has inner join second table on call_sign (but theoretically have been linked first table)

query runs quite slow , feel become slower add more data. realize there things can speed things - not pulling unnecessary data in subqueries , not converting text numbers on fly. there better way structure joins between these 3 tables?

advice appreciated because novice in postgres.

here code:

select  (case      when tmp1.frequency_assigned null      tmp2.lower_frequency     else tmp1.frequency_assigned end) master_frequency, (case      when tmp1.call_sign null      tmp2.call_sign     else tmp1.call_sign end) master_call_sign, (case      when tmp1.entity_type null      tmp2.entity_type     else tmp1.entity_type end) master_entity_type, (case      when tmp1.licensee_id null      tmp2.licensee_id     else tmp1.licensee_id end) master_licensee_id, (case      when tmp1.entity_name null      tmp2.entity_name     else tmp1.entity_name end) master_entity_name, tmp3.market_name         (select cast(replace(frequency_assigned, ',','.') decimal) frequency_assigned,      frequency_upper_band,     f.uls_file_number,     f.call_sign,     entity_type,     licensee_id,     entity_name     combo_fr f inner join combo_en e      on f.call_sign=e.call_sign     order frequency_assigned desc) tmp1 full join     (select cast(replace(lower_frequency, ',','.') decimal) lower_frequency,      upper_frequency,     e.uls_file_number,     mf.call_sign,     entity_type,     licensee_id,     entity_name     market_mf mf inner join combo_en e     on mf.call_sign=e.call_sign     order lower_frequency desc) tmp2 on tmp1.call_sign=tmp2.call_sign inner join      (select en.call_sign,     mk.market_name     combo_mk mk     inner join combo_en en     on mk.call_sign=en.call_sign) tmp3 on tmp2.call_sign=tmp3.call_sign  order master_frequency desc; 

you'll want unwind queries , in 1 join, if can. soemthing like:

select <whatever need> combo_fr f join combo_en e on f.call_sign=e.call_sign join market_mf mf mf on mf.call_sign=e.call_sign join combo_mk mk on mk.call_sign=en.call_sign 

i can't grok you're doing, of join clauses might have become left joins in order deal places call sign or not appear.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -