0

I'm recently developing database api using java, vertx, gradle and mysql. I think I made a correct query but it shows me an error. Anybody knows the problem? Thanks in advance.

Query :

INSERT INTO USER VALUES('[email protected]', 'test', 'password')
WHERE NOT EXISTS (SELECT * FROM USER WHERE email='[email protected]')

Error :

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS (SELECT * FROM USER WHERE email='[email protected]')' at line 1
2

2 Answers 2

2

I believe you should mention column names after INSERT INTO USER .

Something like this;

INSERT INTO USER (email, username, password)
VALUES('[email protected]', 'test', 'password') 
WHERE NOT EXISTS 
(SELECT * FROM USER WHERE email='[email protected]')
Sign up to request clarification or add additional context in comments.

1 Comment

It's been a long time to use sql so I forgot alot :( Thank you so much for reminding me!!
0

I think you should do it like this:

INSERT INTO USER
SELECT '[email protected]', 'test', 'password'
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM USER WHERE email='[email protected]')

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.