Reputation: 1001
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')
Upvotes: 0
Views: 1670
Reputation:
You can write something simple like this:
IF (SELECT COUNT(t.ID) FROM t WHERE t.ID=@id)=1
UPDATE
ELSE
INSERT
Upvotes: 1
Reputation: 1823
I understood your question like this
INSERT INTO table1(value1, value2)
SELECT value1, value2 FROM table2where table2.userID = Id
Upvotes: 1