为什么 WHERE 和 ORDER BY 不兼容?
每当我尝试在同一个 MySQL 查询(无论是在 php 中还是在 C# 中)中使用 WHERE
和 ORDER BY
时,它都不起作用。我总是设法找到另一种方法来做到这一点,但我想知道为什么我们不能同时使用它们......谢谢。
编辑:现在似乎有效,但我向上帝发誓,它以前从未对我有用过,永远!不管它们的放置顺序如何..:无论如何,谢谢你们! :)
Whenever I try using WHERE
and ORDER BY
in the same MySQL query (either in php or c#), it doesn't work. I've always managed to find another way to do this, but I'm wondering why we can't use both of them at once.. Thanks.
EDIT: Seems to work now, but I swear to god it never worked for me before, EVER! No matter of the order they're placed in.. :s Thank you guys anyway! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以同时使用它们,但必须按正确的顺序放置它们。
我建议仔细阅读。
哪里
排序依据
You can use them both, you have to place them in the correct order.
I would suggest reading up on it.
WHERE
ORDER BY
您绝对可以同时使用它们。
You can absolutely use them both at once.
您可以在同一个语句中使用它们。您需要确保它们的顺序正确:
You can use them both within the same statement. You need to make sure that they are in the correct order:
他们非常兼容。我怀疑使用的语法是错误的。要获取有关如何正确编写的建议,请在帖子中包含“错误”语法。
这是有效的 SQL(假设存在这样的模式):
请注意,
ORDER BY
必须出现在末尾。请参阅特定数据库的 SELECT 语法(存在偏差供应商和版本之间)。请注意,C# LINQ 与 SQL“类似”,但不是 SQL。
快乐编码。
They are very compatible. I suspect the syntax used is wrong. To get suggestions on how to write it correctly, include the "wrong" syntax in the post.
This is valid SQL (assuming such a schema exists):
Note that
ORDER BY
has to come at the end.Please see the SELECT syntax for the particular database (there are deviations between vendor and version). Note that C# LINQ is "similar to" SQL, but is not SQL.
Happy coding.
PEBKAC:这不是 MySQL 的问题。
PEBKAC: this is not an issue with MySQL.
它们应该是兼容的......
我能立即想到的唯一一件事是:您在
ORDER BY
之前使用WHERE
吗?在某些 RDBMS 实现中,查询各部分的顺序非常重要。They are supposed to be compatible...
The only thing I can think of offhand is this: Are you using
WHERE
beforeORDER BY
? In some RDBMS implementations, the order of the parts of the query is very important.