这是我的查询:
$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'";
我收到此错误:
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
如果您需要更多意见,请告诉我...
这里出了什么问题?
谢谢
UDP日期:
只是一个问题:我是否还需要指定 a =“此表”和 b =“另一个表”,还是 MySql 通过此代码获取该值?
至于发布的新代码在哪里使用 FROM 和终止符分号,将无法工作并给出此错误:
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
更新2:
$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
变量。)
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'
再次感谢
最佳答案
您没有指定要从中删除的表。尝试:
$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 查询结束后添加了分号。如果您想同时运行这两个版本,则在运行第二个版本之前需要一个分隔符来终止第一个查询。
回复。您的问题编辑有关 MySQL“获取”表的问题 - 如果 a
和 b
是此处的别名,那么不,MySQL 不会不知道 a
和 b
是什么。您需要为表添加别名,或将 a
和 b
替换为实际的表名称。
关于php - SQL语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2972796/