rgbcof
asked on
sql, check if a value exist before adding
I didn't specify that a column has to be unique in a table, but it is too late. How do write an sql statement to insert only if a value is not there in that column.
-- For example, if 'dave' already exists, then don't insert
insert into math_score (l_name, score) values ('dave', 98);
-- For example, if 'dave' already exists, then don't insert
insert into math_score (l_name, score) values ('dave', 98);
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I guess it works on some database but not postgres. No worries, I will make two calls.
ASKER
ERROR: syntax error at or near "IF"
LINE 1: IF NOT EXISTS (SELECT * FROM
^