Friday 12 January 2018

mysql multiple table DELETE rows syntax error

itemprop="text">

how come this
query:



select * FROM
`store_catalog_product_option` JOIN `store_catalog_product_option_type_value` WHERE
`product_id`=15676 AND `store_catalog_product_option_type_value`.`sku` LIKE '%UNIT_%'



retrieve
datas




but replacing



 select *



with



 delete




as such



 delete FROM
`store_catalog_product_option` JOIN `store_catalog_product_option_type_value` WHERE
`product_id`=15676 AND `store_catalog_product_option_type_value`.`sku` LIKE
'%UNIT_%'


give syntax
error:





SQLSTATE[42000]: Syntax error or access violation: 1064 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 'JOIN
store_catalog_product_option_type_value WHERE
product_id=15676 AND `sto' at line
1




class="post-text" itemprop="text">
class="normal">Answer



For href="http://dev.mysql.com/doc/refman/5.7/en/delete.html" rel="nofollow">multi-table
deletes,





For the first multiple-table syntax, only matching rows from the tables listed
before the FROM clause are deleted. the second multiple-table
syntax, only matching rows from the tables listed in the FROM
clause (before the USING clause) are deleted.




DELETE
t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3
WHERE t1.id=t2.id AND
t2.id=t3.id;





Or:




DELETE
FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3
WHERE t1.id=t2.id AND
t2.id=t3.id;


And for
LEFT JOIN, you should use something
like




DELETE t1 FROM t1
LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS
NULL;

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...