0

So, I am trying to add a data if a value in field does not exist. I am keep getting syntax error and not sure where I am getting it wrong.

INSERT INTO COMPANY_TABLE(company_name, company_phone, company_url)
VALUES ('test','010-4843-0000','www.company.com')
WHERE NOT EXISTS (SELECT * FROM COMPANY_TABLE WHERE company_name = 'test');

This is my code. I am using H2 database

1
  • 1
    What is the error message? (append to the question) ... also, add a tag for the DB vendor (MySQL, sqlite, etc) that you use. Commented Nov 12, 2022 at 20:06

1 Answer 1

1

You're trying to combine a values table constructor with syntax of a select query

You can insert into a table using select:

INSERT INTO COMPANY_TABLE(company_name, company_phone, company_url)
SELECT 'test','010-4843-0000','www.company.com'
WHERE NOT EXISTS (SELECT * FROM COMPANY_TABLE WHERE company_name = 'test');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.