简体   繁体   中英

Error in query (1052): Column 'register_log_id' in field list is ambiguous

The POS software I use has recently updated and split the info I need to download into 2 tables. I thought I had the issue sorted but I'm getting the error in the title. Here is the code:

SELECT register_log_id, p.register_id, p.employee_id_open, 
p.employee_id_close, p.shift_start, p.shift_end, s.open_amount, 
s.close_amount, s.payment_sales_amount, s.total_payment_additions, 
s.total_payment_subtractions, p.notes 
FROM phppos_register_log p JOIN
phppos_register_log_payments s
ON p.register_log_id = s.register_log_id
WHERE shift_end <> '0000-00-00 00:00:00' AND register_log_id > 2607

In the WHERE clause you need to add the alias to register_log_id so MySQL knows which table you are trying to limit it by.

So either:

WHERE shift_end <> '0000-00-00 00:00:00' AND p.register_log_id > 2607

or

WHERE shift_end <> '0000-00-00 00:00:00' AND s.register_log_id > 2607

You don't have the issue with shift_end because it must only be in one of the tables.

Column 'register_log_id' in field list is ambiguous

This simply means register_log_id is not an unique column name and exists in more than one table you are referencing in your query. Simply prefix that field with table name and you are done.

Column register_log_id in field list is ambiguous

That means that the column: register_log_id appears in more than one table. Simply fully qualify it as: tableName.tableColumn

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