Dilini Wasana
Dilini Wasana

Reputation: 267

How to use DUPLICATE KEY UPDATE sql

How to use ON DUPLICATE KEY UPDATE for non auto increment key(reg_id) ? I'll insert that values from another table.So i want to insert a new raw if there aren't a sending reg_id if there is i want to update values in other columns ...

My SQL create table

CREATE TABLE IF NOT EXISTS  student_subjects(

    reg_id INT(4),
    primary_maths VARCHAR(100),
    .....................etc 

MY SQL Insert

           INSERT INTO student_subjects(reg_id,primary_maths ,.................
    ........etc) VALUES(?,?,...............etc) ON DUPLICATE 
KEY UPDATE reg_id=VALUES(reg_id);

Upvotes: 0

Views: 54

Answers (1)

Maxim Khan-Magomedov
Maxim Khan-Magomedov

Reputation: 1336

But it's written in Manual

Something like ... on duplicate key update reg_id = reg_id + 1 instead of values(reg_id)

or ... on duplicate key update primary_maths = 42, lalala = 'hohoho'

Upvotes: 1

Related Questions