Insert if nothing exists [duplicate]
Clash 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);