Sql语法错误 [英] Sql syntax error
问题描述
这是我的查询:
$query="Delete b
Where Exists
(
Select 1
From a
Where a.poster_password = '$pass'
And a.ad_id = '$id'
And a.classified_id = b.classified_id
)
Delete a
Where a.poster_password = '$pass'
And a.ad_id = '$id'";
我收到此错误:
您的SQL语法有错误;请检查与您的MySQL服务器版本对应的手册,以获取正确的语法在Where Exists(Select 1 From a Where aosterstat line 2
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 Exists ( Select 1 From a Where a.poster_p' at line 2
如果您需要更多输入,请告诉我...
If you need more input let me know...
这里有什么问题?
感谢
UDPATE:
只是一个问题:还有a =this table和b =另一个表或者MySql是否通过这个代码得到了?
Just a Q: Do I need to specify also that a = "this table" and b = "another table" or does MySql get that by this code?
一个终止符分号,无法工作并给出此错误:
As for the new code posted where to use FROM and a terminator semicolon, wont work and give this error:
您的SQL语法有错误;请检查与MySQL对应的手册服务器版本,使用正确的语法在第10行附近使用'Delete FROM a Where a.poster_password ='xxxxxxxxxxxxxxxxxxxxx'
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 'Delete FROM a Where a.poster_password = 'xxxxxxxxxxxxxxxxxxxxx' at line 10
UPDATE2:
$query="Delete FROM $sql_table
Where Exists
(
Select 1
From classified
Where classified.poster_password = '$pass'
And classified.ad_id = '$id'
And classified.classified_id = $sql_table.classified_id
);
Delete FROM classified
Where classified.poster_password = '$pass'
And classified.ad_id = '$id'";
当我 echo $ query
:(fordon在这种情况下 $ sql_table
variable。)
And when I echo $query
: (fordon is in this case $sql_table
variable.)
Delete FROM fordon
Where Exists
(
Select 1
From classified
Where classified.poster_password = 'xxxxx'
And classified.ad_id = 'motorbat_166250627'
And classified.classified_id = fordon.classified_id
);
Delete FROM classified
Where classified.poster_password = 'xxxxx'
And classified.ad_id = 'motorbat_166250627'
再次感谢
推荐答案
您并未指定要删除的表格。
You're not specifying the tables to delete from. Try:
$query="Delete FROM b
Where Exists
(
Select 1
From a
Where a.poster_password = '$pass'
And a.ad_id = '$id'
And a.classified_id = b.classified_id
);
Delete FROM a
Where a.poster_password = '$pass'
And a.ad_id = '$id'";
在第一次DELETE查询结束后,我还添加了一个分号。如果你想同时运行两个,你需要一个分隔符来终止第一个查询,在您运行第二个版本之前。
I've also added in a semicolon after the end of the first DELETE query. If you want to run both at the same time, you'll need a separator to terminate the first query, before you run the second version.
Re。 $ c> a 和 b
是别名,那么没有,MySQL不知道 a
和 b
是您需要别名表,或替换 a
和 b
与实际表名称。
Re. your question edit about MySQL "getting" the tables - if a
and b
are aliases here, then no, MySQL doesn't know what a
and b
are. You'll need to alias the tables, or replace a
and b
with the actual table names.
这篇关于Sql语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!