mysql删除查询,多个内部连接

7cjasjjr  于 2021-07-05  发布在  Java
关注(0)|答案(1)|浏览(339)

我想使用主键orderid从数据库中删除一个“order”。orderid是orderitem中的外键,orderitem在fooditem中有一个名为fooditemid的外键,fooditem在menu中有一个名为menuid的外键。
以下是我的疑问:

"DELETE FROM orders, orderitem, fooditem, menu " +
            "USING orders " +
            "INNER JOIN orderitem " +
            "WHERE orderID = " + "'" + orderID + "' " + " AND orders.orderID = orderItem.orderID " +
                    "INNER JOIN foodItem " +
                    "WHERE orderItem.foodItemID = foodItemID.foodItemID " +
                    "INNER JOIN Menu " +
                    "WHERE foodItem.menuID = menu.menuID";

我在用javafx编码。。我收到的错误是:
原因:java.sql.sqlsyntaxerrorexception:您的sql语法有错误;请查看与mysql服务器版本对应的手册,以获取在第1行的“inner join fooditem where orderitem.fooditemid=fooditemid.fooditemid inner joi”附近使用的正确语法

nfs0ujit

nfs0ujit1#

你不加入 WHERE ,你加入 ON 一些东西。所以

"DELETE FROM orders, orderitem, fooditem, menu " +
"USING orders " +
"INNER JOIN orderitem " +
"ON orderID = " + "'" + orderID + "' " + " AND orders.orderID = orderItem.orderID " +
"INNER JOIN foodItem " +
"ON orderItem.foodItemID = foodItemID.foodItemID " +
"ON JOIN Menu " +
"ON foodItem.menuID = menu.menuID";

还有,这部分

"ON orderID = " + "'" + orderID + "' " + "

正在等待sql注入。你应该改用事先准备好的语句。如何使用它们取决于用于连接数据库的库/框架(您没有指定)。

相关问题