0

Is there a SQL command for inserting data into a row where the id = the table id, and if it doesnt exists then insert into a new row?

Something like: ('INSERT INTO USERS IF EXISTS WHERE userID=ID')

Mac Luc
  • 925
  • 5
  • 14
  • 31

2 Answers2

1

I understood your question like this

INSERT INTO table1(value1, value2) 
SELECT value1, value2 FROM table2where table2.userID =  Id
Narayan Yerrabachu
  • 1,486
  • 1
  • 13
  • 27
1

You can write something simple like this:

IF (SELECT COUNT(t.ID) FROM t WHERE t.ID=@id)=1
    UPDATE
ELSE
    INSERT