开发者

MySql. What is there error on this insert+select+where statement?

What is wrong with this statement? It works with sqlite and MS sql (last time i tested it)

I would like a select un开发者_如何学Goless there is no match with name or email. Then i would like to insert. I have it as one statement because its easy to keep concurrent safe as one statement. (its not that complex of a statement).

INSERT INTO `user_data` (
`last_login_ip`, `login_date`,
...) SELECT 
@0,
@14 WHERE not exists (SELECT * FROM `user_data` WHERE `name` = @15 OR 
`unconfirmed_email` = @16 LIMIT 1);

Exception

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 'WHERE not exists (SELECT * FROM `user_data` WHERE `name` = 'thename' OR 
`unconfirmed' at line 31


You have no FROM clause in your SELECT. If you look carefully at the documentation for SELECT you can see that although FROM is optional, if there is a WHERE clause then the FROM is required:

SELECT ...
[FROM table_references
[WHERE ...]
...]

If you don't need a table you can use FROM DUAL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜