MySQL 排序错误
如果我运行以下查询:
select * from mysql.user order by abcdef;
MySQL 会抛出以下错误:
错误 1054 (42S22):未知列 “订单子句”中的“abcdef”
如果我运行以下类似的查询:
select * from mysql.user order by "abcdef";
MySQL 现在运行查询并忽略 order by 子句(因为 mysql.user 表缺少名为 'abcdef' 的列)。
这是 MySQL 中的错误吗?当短语用引号括起来时,为什么您希望 order by 默默地失败?在不存在的列上运行 order by 时,错误消息不是合适的吗?
If I run the following query:
select * from mysql.user order by abcdef;
MySQL throws the following error:
ERROR 1054 (42S22): Unknown column
'abcdef' in 'order clause'
If I run the following similar query:
select * from mysql.user order by "abcdef";
MySQL now runs the query and disregards the order by clause (since the mysql.user table lacks a column called 'abcdef').
Is this a bug in MySQL? Why would you want the order by to fail silently when the phrase is in quotes? Wouldn't an error message be appropriate when running order by on a non-existent column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它不会忽略它,它按字符串“abcdef”排序,而不是列。它完全按照您的要求进行操作:按任意字符串排序(很可能根本不执行任何操作)。
大多数 RDBMS 不接受按常量排序(这没有意义),但 MySQL 接受。
It doesn't disregard it, it orders by the string "abcdef", not the column. It does exactly what you ask : ordering by some arbitrary string (which most likely does nothing at all).
Most RDBMS doesn't accept to order by a constant (it doesn't make sense), but MySQL does.
当您不使用引号时,它会假设您引用的列名不存在。
这是正确的功能
When you are not using quotes, it would assume that you are referring to a column name, which does not exist.
This is correct functionallity
order by 期望您想要排序的字段,如果您希望它升序,您可以将 asc 放在它旁边,如果您希望它降序,您可以放置如下的 desc
The order by expects the field you want to order and if you want it ascending you put asc next to it, and if you want it descending you put a desc like as follows