Link to home
Create AccountLog in
Avatar of rgbcof
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);

ASKER CERTIFIED SOLUTION
Avatar of lludden
lludden
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of rgbcof
rgbcof

ASKER

POSTGres is comlaining...
ERROR:  syntax error at or near "IF"
LINE 1: IF NOT EXISTS (SELECT * FROM
        ^
Avatar of rgbcof

ASKER

I guess it works on some database but not postgres.  No worries, I will make two calls.