Insert if nothing exists [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Insert if nothing exists [duplicate]



This question already has an answer here:



I want to insert rows if nothing exists in a table.



Something like that:


WHEN NOT EXISTS (SELECT * FROM Students) THEN
INSERT INTO Students (name) VALUES ("Foo Bar"), ("Bar Foo")



But it causes Error: SQLITE_ERROR: near "WHEN": syntax error


Error: SQLITE_ERROR: near "WHEN": syntax error



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




1 Answer
1



You could use:


INSERT INTO Students (name)
SELECT 'Foo Bar' AS name
WHERE NOT EXISTS (SELECT * FROM Students);

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS