I am trying to update on duplicate record in MySQL,
I have a table with many column but i want to update only some column from another table with same desc as current table but it is not updating records.
my query is:
insert into backup_prochart.symbol_list(ticker,end_date,cur_date) select ticker,t.end_date,t.cur_date from prochart.symbol_list t where ticker=t.ticker and ticker= 'MAY17' on duplicate key update end_date=t.end_date,cur_date=t.cur_date;
another query i tried
insert into backup_prochart.symbol_list(ticker,end_date,cur_date) select t.ticker,t.end_date,t.cur_date from prochart.symbol_list t where ticker=t.ticker and t.ticker= 'MAY17' on duplicate key update end_date=t.end_date,cur_date=t.cur_date;
can anyone tell me whats wrong with my query.?
You could try :
Of course the column "ticker" must be defined as unique for the table "backup_prochart.symbol_list".
try this. its worked for me.
Insert into employee_projects(employee_id,proj_ref_code) select ep.employee_id,ep.proj_ref_code from hs_hr_emp_projects_history ep where not exists ( select 1 from employee_projects p where ep.employee_id = p.employee_id and ep.proj_ref_code = p.proj_ref_code )
You say that you are trying to update a record, but you are using an
INSERT
statement. Shouldn't you be usingUPDATE
instead ofINSERT
?Difference between
INSERT
andUPDATE
can be found hereNote that you can use
UPDATE
andSELECT
in a single query.