Question : Update a table based on the FIRST record of a join (mySql)

Hi

we have a problem and require to UPDATE a date field in a table from the FIRST date field in a second table, both tables have an auto incriment field and this WILL be in date order as well

Ive tried several joins but keep hitting an error

the table details are as follows

sql=" UPDATE orders,contact_history SET order_date=cont_date where orders.orderID=contact_history.orderID group by orders.order ID order by contact_history.cont_id;"

this is what were thinking but feels wrong at the group point

Answer : Update a table based on the FIRST record of a join (mySql)

something like this:
1:
2:
3:
4:
5:
6:
create table tmp_dt select orderID, max(cont_date) max_cont_date from contact_history group by orderID
;
update orders set order_Date=( SELECT max_cont_date  FROM tmp_dt where tmp_dt.orderID=orders.orderID  )
;
drop table tmp_dt
;
Random Solutions  
 
programming4us programming4us