简体   繁体   English

在MySql中加入DELETE? 如何?

[英]Join DELETE in MySql? How to?

I have this: 我有这个:

$query="DELETE FROM classified, $sql_table WHERE classified.ad_id = '$id' AND classified.classified_id = $sql_table.classified_id AND classified.poster_password='$pass'";

I get this error: 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 classified.ad_id = 'Bmw_M3_E46_Full_29920' AND classified.cla' at line 1 我收到此错误: 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 classified.ad_id = 'Bmw_M3_E46_Full_29920' AND classified.cla' at line 1 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 classified.ad_id = 'Bmw_M3_E46_Full_29920' AND classified.cla' at line 1

Any help? 有帮助吗?

As you can see the $sql_table is linked to the classifieds table with the fields classified_id I need to JOIN DELETE somehow. 正如您所看到的,$ sql_table链接到带有classified_id字段的分类表,我需要以某种方式加入DELETE。

Basically classified table is the main table, then every category has its own tables with vehicle data. 基本上分类的表是主表,然后每个类别都有自己的车辆数据表。 classified table has a field called classified_id which is the same as the 分类表有一个名为classified_id的字段,它与

Here is the full query echoed: 这是回显的完整查询:

DELETE FROM classified, vehicles WHERE classified.ad_id = 'Bmw_M3_E46_410811305' AND classified.classified_id = vehicles.classified_id AND classified.poster_password='some_password'

Why isn't this working, Should it be so hard to delete from multiple tables? 为什么这不起作用,是否应该从多个表中删除这么难?

Thanks 谢谢

DELETE a, b FROM
classified as a, $sql_table as b
WHERE
classified.ad_id = '$id' 
AND classified.classified_id = $sql_table.classified_id 
AND classified.poster_password='$pass'";

Source: Source 资料来源: 来源

The MySQL website indicates that you may need to declare your tables after the DELETE statement: MySQL网站表明您可能需要在DELETE语句之后声明表:

Multiple-table syntax: 多表语法:

DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
  tbl_name[.*] [, tbl_name[.*]] ...
  FROM table_references
  [WHERE where_condition]

对于初学者,检查多表删除的语法您需要指定要从中删除的表

DELETE classified.*, vehicles.* FROM classified, vehicles

i just has detect something but didn't know its really working or not, try to put what you want to tied from two tables first like this: 我只是检测到了一些东西,但不知道它是否真正起作用,试着把你想要的东西从两个表中加入,如下所示:

 DELETE FROM classified, vehicles WHERE classified.classified_id = vehicles.classified_id
AND classified.ad_id = 'Bmw_M3_E46_410811305' 
AND classified.poster_password='some_password'

then only what exact value in the column you want to delete. 那么只有你要删除的列中的确切值。 please try n revert. 请尝试恢复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM