开发者

MySql Where-Subquery syntax error

开发者 https://www.devze.com 2023-01-04 05:18 出处:网络
This code worked in Sqlite which i have more experience with. I cant figure out whats wrong here. If it helps SELECT 1 FROM Post WHERE body =\'a\'; doesnt give me a syntax error but this does

This code worked in Sqlite which i have more experience with. I cant figure out whats wrong here. If it helps SELECT 1 FROM Post WHERE body = 'a'; doesnt give me a syntax error but this does

select 1 WHERE NOT EXISTS (SELECT 1 FROM Post WHERE body = 'a' ) ;
开发者_如何转开发

code:

INSERT INTO `Post` (
`name`,
...
`date`) select 
@0,
...
@6 WHERE NOT EXISTS (SELECT 1 FROM Post WHERE body =  @7 ) 

error

near 'WHERE NOT EXISTS (SELECT 1 FROM Post WHERE body =  'text' )' at line 15


Try using dual as the dummy table in your select (see here).

INSERT INTO `Post` (
`name`,
...
`date`) select 
@0,
...
@6 
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM Post WHERE body =  @7 ) 

From the referenced link:

You are allowed to specify DUAL as a dummy table name in situations where no tables are referenced:

mysql> SELECT 1 + 1 FROM DUAL; -> 2

0

精彩评论

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