Reputation: 11
I have two tables 2)- First Table where I store all product details like name, price, weight, etc. 1)- Second Table where I store updated price with product_id
I want to fetch an updated price with product_id from the second table but if the product_id is not available on the second table then the price will come from first table.
Upvotes: 0
Views: 80
Reputation: 17655
Left join and coalesce
select t1.pid,name, coalesce(t2.price,t1.price), weight
from t1
left join t2 on t1.pid = t2.pid;
Upvotes: 2