I have a query that pulls a lot of the information I need filtered by multiple WHERE clauses. However, I don’t want the my main table (inv_data in this case) to be affected by all the WHERE clauses. Is there any way to choose which tables get affected by which WHERE?
Here’s my current query:
$query_ats = "SELECT
i.prod_cd as product,
i.descrip as description,
i.in_stock as current_stock,
SUM(p.log_qty) as purchase_order,
SUM(l.order_qty + e.order_qty) as total_so
from
inv_data as i
inner join plog as p
on i.prod_cd = p.prod_cd
inner join ord_log as l
on i.prod_cd = l.prod_cd
inner join ediordlg as e
on i.prod_cd = e.prod_cd
where
i.class_cd = 'ALG7'
AND
dateadd(day, p.EST_DT, '18001228') BETWEEN getdate() and dateadd(day, 14, getdate())
AND
dateadd(day, l.SHIP_DT, '18001228') BETWEEN getdate() and dateadd(day, 14, getdate())
AND
dateadd(day, e.SHIP_DT, '18001228') BETWEEN getdate() and dateadd(day, 14, getdate())
group by
i.prod_cd,
i.descrip,
i.in_stock,
order by
i.prod_cd ASC";
Table i (inv_data) is my main table that I do not want affected by any of the dateadd clauses.
Thanks!
Left outer join the conditions and move the conditions to the
onclause: