with order_product_variation_details as
(
Select product_id, variation_id
from
(
Select o.*,v.id as variation_id from (select * from silver.supply__order_details where sub_order_num = '106459531525120384_1')o --Filter sub_order_num here
left join silver.supply__product_supplier_map psm on o.product_id = psm.product_id and o.supplier_id = psm.supplier_id
left join silver.inventory__variations v on psm.scale_id = v.scale_id and o.variation = v.name
)A
)
Select supplier_id, product_id, variation_id, inventory_updated_timestamp AT TIME ZONE 'Asia/Calcutta' as inventory_update_time,source, supplier_oos, live_inventory as current_value, all_inventory as older_value, projected_orders, pending_orders, dispatched_orders from silver.inventory__inventory_product_inventory_log_v2
where product_id in (select distinct product_id from order_product_variation_details) and variation_id in (select distinct variation_id from order_product_variation_details)
order by inventory_updated_timestamp desc