How to update one table from another table based on some priority that depends on where clause?
问题 I have table A with product_id,cost,year,quarter,... etc columns. I have another table B with product_id,base_cost,current_year,p_year,p_quarter,p_order columns. I want to write an update query to update A from B. My conditions are - WHERE A.product_id=B.product_id and A.year=B.current_year and (A.year=B.p_year and A.quarter>B.p_quarter) or A.year>B.p_year and A.cost=0; But the problem is, with these conditions if i have more than one rows in B then i only want to update from the row of B