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 cla开发者_StackOverflow中文版ssified.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
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.
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
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:
Multiple-table syntax:
DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
tbl_name[.*] [, tbl_name[.*]] ...
FROM table_references
[WHERE where_condition]
For starters check syntax for multiple table delete You need to specify tables from which to delete
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.
精彩评论