Monthly Archives: July 2019

Delete records from multiple tables

This is sample query to delete record from multiple tables.

Specify all joined tables to get the list but can specify records in which tables to be 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;

Reference

https://dev.mysql.com/doc/refman/8.0/en/delete.html (refer section –┬áMulti-Table Deletes)

MySQL Error Code 1166. Incorrect column name

Got this error while importing csv to table in MySQL database using sequel pro.

This error normally because of extra space in field name that mysql cannot accept.

But sometimes you just can’t find where is the extra space.

One way to solve is add additional column, when import, just ignore the last field and you can import it as usual.