MySQL Error number: 3065; Symbol: ER_FIELD_IN_ORDER_NOT_SELECT; SQLSTATE: HY000 报错 故障修复 远程处理
文档解释
Error number: 3065; Symbol: ER_FIELD_IN_ORDER_NOT_SELECT; SQLSTATE: HY000
Message: Expression #%u of ORDER BY clause is not in SELECT list, references column ‘%s’ which is not in SELECT list; this is incompatible with %s
。
错误说明:将一个字段放在ORDER BY子句中但该字段未在SELECT子句中选择时可能引发MySQL的ER_FIELD_IN_ORDER_NOT_SELECT错误。
常见案例
SELECT id
FROM products
ORDER BY name
如果客户端尝试执行上述查询,MySQL将报告ER_FIELD_IN_ORDER_NOT_SELECT错误,因为ORDER BY子句中的name字段没有在SELECT子句中选择。
解决方法:要修复此错误,请确保ORDER BY子句中的字段在SELECT子句中被选择。在上面的案例中,需要将name字段添加到SELECT子句中:
SELECT id, name
FROM products
ORDER BY name