I have a query below, which retrieves data from 3 tables.
select *
from vendor_allocation as va, district as d, vendor as v
where va.district_id = d.id and va.vendor_id = v.id
In the result there are many null columns and it takes about 315 msec to execute. I would need to omit the null columns and execute the query faster. I tried using COALESCE but dint get expected results. Please help.
FROM
clause. Always use proper, explicitJOIN
syntax.select *
should never be used in production queries.select *
returns all columns. Define the columns you want to return by listing them (egselect somecolumn, someothercolumn, jcwashere from somekindatable
cross join
i.e.Cartesian Product
. Each row fromvendot_allocation
is combined with each row ofdistrict
which is then combined withvendor
. This results in a huge amount ofmeaningless
data