从php/mysql中的两个表中删除一条记录 [英] delete a record from two tables in php/mysql

查看:111
本文介绍了从php/mysql中的两个表中删除一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码从船表和另一个表中的关联资格中删除船":

I'm trying to delete a "boat" from boat table and associated qualifications in another table using the following code:

DELETE FROM tbl_boat, tbl_qualifications 
WHERE tbl_boat.BT_ID = '$bt_id' AND tbl_boat.BT_ID = tbl_qualifications.BT_ID;

问题是我收到以下错误:

The problem is I'm receiving following error:

1064-您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第2行的'WHERE tbl_boat.BT_ID = 113 AND tbl_boat.BT_ID = tbl_'附近使用.

对此表示感谢.

推荐答案

您需要执行两次删除操作:

You need to perform two delete :

-首先删除所有关联...
从tbl_qualifications删除,其中BT_ID ='$ bt_id';

-- DELETE all associations first ...
DELETE FROM tbl_qualifications WHERE BT_ID = '$bt_id';

-...然后删除船
从tbl_boat删除,其中BT_ID ='$ bt_id';

-- ... then delete the boat
DELETE FROM tbl_boat WHERE BT_ID = '$bt_id';

这篇关于从php/mysql中的两个表中删除一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆