简体   繁体   中英

mysql #1054 - Unknown column in 'where clause' when update, but can be selected

I'm quite confused with this problem.

I have a table of purchase_list that about like this:

purchase_code  item  unit  order_amount  recived_amount  price
TRX-000001        1     1             0              85  14200

Then i try to update that record with this query:

UPDATE `purchase_list` 
SET `order_amount`='85'
WHERE `purchase_code`='TRX-000001' AND `item`='1' AND `unit`='1'

And end up with error:

#1054 - Unknown column 'unit' in 'where clause'

But when i do SELECT query:

SELECT `order_amount`
FROM `purchase_list` 
WHERE `purchase_code`='TRX-000001' AND `item`='1' AND `unit`='1'

it does show result:

order_amount
           0

And when I click phpmyadmin's Simulate query button, it does says:

Matched rows: 1

but still it can't execute the update query. Any idea how to solve my problem?

Check datatype of unit column and try with

AND `unit`=1

If data type of unit is int else share table structure of `purchase_list.

The most likely cause of your problem is a trigger on purchase_list . You should check if that is the case.

A secondary possibility is that the two queries are pointing to different databases with different table structures.

Sometimes this error occurs due to the use of same quotes (single ' or double ") for column name and value. For example, in my case: I used these two queries

Query #1:

UPDATE 'customerinvoice' 
SET 'invoice_status' = 2 
WHERE 'invoice_no' = '20200907202602_6'

Query #2:

'UPDATE customerinvoice 
 SET invoice_status = 2 
 WHERE invoice_no = 20200907202602_6'

and it throws this error.

(1054, "Unknown column '20200907202602_6' in 'where clause'")

I solved this issue using:

Query #1

UPDATE 'customerinvoice' 
SET 'invoice_status' = 2 
WHERE 'invoice_no' = "20200907202602_6"

Query #2:

'UPDATE customerinvoice 
 SET invoice_status = 2 
 WHERE invoice_no = "20200907202602_6" '

Note: I am working in python and database is MySQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM