I have two tables: -
manu_table product_id, manufacturer 1, ford 2, ford 3, toyota product_table product_id, score 1, 80 2, 60 3, 40
I want to keep the top product_id rating for each manufacturer in the pivot table: -
summary_table manufacturer, max_score ford, 1 toyota, 3
So far I have: -
UPDATE summary_table st SET max_score = ( SELECT product_id FROM ( SELECT manufacturer, product_id, max(score) as ms FROM manu_table LEFT JOIN product_table USING (product_id) group by product_id) t) WHERE st.manufacturer = manu_table.manufacturer;
You have problems ... All help is greatly appreciated.
source share