Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

mysql insert or update

schedule_id int auto_increment primary key
row int
column int
event_id int

if row and column is already there
then update event_id (not insert)

2 queries generates error
insert into schedule (row, column, event_id)
  SELECT schedule.row,schedule.column,1 FROM schedule
   ON DUPLICATE KEY UPDATE event_id=1


insert into schedule (row, column, event_id)
  values (3,2,1)
   ON DUPLICATE KEY UPDATE event_id=1;




and this query keeps on inserting duplicate values with a new schedule_id primary key autoincrement

INSERT INTO schedule (`row`,`column`,`event_id`) VALUES (1,2,3)
  ON DUPLICATE KEY UPDATE `event_id`=3
ASKER CERTIFIED SOLUTION
Avatar of johanntagle
johanntagle
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

I do not want repeats of

BOTH
row int
column int

currently in the table:
row=2 column=3

new inserts
row=2 column=1  -> do this insert
row=2 column=3  -> do only an update of event_id
Yes I understand that, and I already told you that you need to create the unique constraint.  You also haven't given the exact error message you are encountering.
Avatar of rgb192

ASKER

thanks
uc works