Here is my query
SELECT item.item, item.id as itemID,item.item_sku,O.serial_no,transaction.id, transaction.t_price, transaction.t_unit, transaction.total_amount, transaction.transaction_type, transaction.comment, transaction.created from transaction
LEFT JOIN item ON transaction.item_id = item.id
LEFT JOIN order O ON transaction.order_no=o.order_no
WHERE transaction_type='buy' ORDER BY transaction.created DESC
但是它显示了这个错误..为什么??
答案 0 :(得分:2)
ORDER
是reserved word,所以你需要逃避它。检查此Stackoverflow answer,了解如何使用反向勾号来转义查询中的保留字。
请检查一下:
SELECT item.item, item.id as itemID,item.item_sku,O.serial_no,transaction.id, transaction.t_price, transaction.t_unit, transaction.total_amount, transaction.transaction_type, transaction.comment, transaction.created
FROM transaction
LEFT JOIN item ON transaction.item_id = item.id
LEFT JOIN `order` O ON transaction.order_no = o.order_no
WHERE transaction_type='buy'
ORDER BY transaction.created DESC
答案 1 :(得分:0)
使用ALIAS时可以写一个较短的表格。
SELECT
i.item
, i.id as itemID
, i.item_sku
, o.serial_no
, t.id
, t.t_price
, t.t_unit
, t.total_amount
, t.transaction_type
, t.comment
, t.created
FROM transaction
LEFT JOIN item i ON t.item_id = i.id
LEFT JOIN `order` o ON t.order_no=o.order_no
WHERE transaction_type='buy'
ORDER BY t.created DESC;