technical skills grow

Responsive Ads Here

Wednesday, August 25, 2021

DUPLICATE KEY UPDATE IN MYSQL

Ex: we want to insert in table after delete some data but again insert data in table it is give error duplicate key error .

insert ignore emp_details ( id , name , dept_id ) 

values

select id , name , dept_id  from temp_table as t1 

on duplicate key update

id=t1.id , name =t1.name , dept_id=t1.dept_id ;

 

 SELECT b.AREA_ID , DATE(`T_DATE`) T_DATE ,`F_DATE` ,a.`STATE` ,a.`DISTRICT` ,`TMIN`,`TMAX` ,`RHMAX` ,`RHMIN` ,RAIN,WIND_SPEED,WIND_DIR
 FROM FORECAST_30DAYS_DATA_RAW a , FORECAST_30DAYS_MASTER b
 where lower(a.STATE) = lower(b.STATE)  and lower(a.DISTRICT)=lower(b.DISTRICT)
 and t_date = (select max(t_date) from FORECAST_30DAYS_DATA_RAW)
 ON DUPLICATE KEY UPDATE b.AREA_ID=a.area_id, b.T_DATE=a.T_DATE,
   b.F_DATE=a.F_DATE, b.TMIN=a.TMAX, b.TMAX=a.TMIN,
  b.RHMAX=a.RHMAX ,b.RHMIN=a.RHMIN,b.RAIN=a.RAIN,b.WIND_SPEED=a.WIND_SPEED,
  b.WIND_DIR=a.WIND_DIR ;

No comments:

Post a Comment

Powered by Blogger.

Labels

Contact Form

Name

Email *

Message *

Search This Blog

Blog Archive

Ad Code

Responsive Advertisement

Recent Posts