首页 > 解决方案 > 错误代码:1054 'where 子句'中的未知列'billId'

问题描述

尽管有很多与此类似的问题。它与其他人完全不同。而且我无法找到纠正确切错误的方法。这就是为什么在这里发布它。

我正在编写一个查询,我需要使用一个 ID 删除多个表上的条目。

我有estimate_id。我想删除 bill 表还有 bill_details 表。在 bill_details tbl 中存储了 bill_id。所以我写了一个查询来从 bill tbl 中进行选择。但是在 where 子句中使用它时最终出错。

存储过程在这里:

CREATE DEFINER=`root`@`localhost` PROCEDURE `delete_by_estimation_no`(in_estimation_id int)
BEGIN
SET SQL_SAFE_UPDATES = 0;

select (id)projId from projects WHERE estimation_no=in_estimation_id; 
DELETE FROM projects WHERE estimation_no=in_estimation_id; 

DELETE FROM estimation WHERE id=in_estimation_id; 
DELETE FROM estimation_details WHERE estimation_id=in_estimation_id;

select (id)billId from bill where estimation=in_estimation_id;
DELETE FROM bill WHERE estimation=in_estimation_id; 
DELETE FROM bill_details WHERE bill_id=billId; 

select (id)invoiceId from invoice where estimation=in_estimation_id;
DELETE FROM invoice WHERE estimation_no=in_estimation_id; 
DELETE FROM invoice_details WHERE invoice_id=invoiceId; 
 
select (id)crId from change_request where project_id=projId;
DELETE FROM change_request WHERE project_id=projId; 
DELETE FROM change_request_details WHERE cr_id=crId; 

END

我收到这个错误。

错误代码:1054 'where 子句'中的未知列'billId'

[![Bill][1]][1]

账单详情

项目

标签: mysqlstored-proceduresmysql-workbenchmysql-error-1054

解决方案


bill_details 中没有 billId 列,但您可以通过查询从两个表中删除

    DELETE bill, bill_details
    FROM bill 
    INNER JOIN bill_details ON bill.id = bill_details.bill_id

(假设连接键是 id 和 bill_id)


推荐阅读