为什么 WHERE 和 ORDER BY 不兼容?

发布于 2024-11-27 16:48:27 字数 215 浏览 1 评论 0原文

每当我尝试在同一个 MySQL 查询(无论是在 php 中还是在 C# 中)中使用 WHEREORDER 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

陪你搞怪i 2024-12-04 16:48:27

您可以同时使用它们,但必须按正确的顺序放置它们。

SELECT *
FROM table t
WHERE t.field
ORDER BY t.field1

我建议仔细阅读。

哪里

排序依据

You can use them both, you have to place them in the correct order.

SELECT *
FROM table t
WHERE t.field
ORDER BY t.field1

I would suggest reading up on it.

WHERE

ORDER BY

小傻瓜 2024-12-04 16:48:27

您绝对可以同时使用它们。

You can absolutely use them both at once.

玩心态 2024-12-04 16:48:27

您可以在同一个语句中使用它们。您需要确保它们的顺序正确:

SELECT *
  FROM Table
 WHERE Column = Something
 ORDER
    BY ColumnId

You can use them both within the same statement. You need to make sure that they are in the correct order:

SELECT *
  FROM Table
 WHERE Column = Something
 ORDER
    BY ColumnId
哭泣的笑容 2024-12-04 16:48:27

他们非常兼容。我怀疑使用的语法是错误的。要获取有关如何正确编写的建议,请在帖子中包含“错误”语法。

这是有效的 SQL(假设存在这样的模式):

SELECT age
FROM users
WHERE age > 42
ORDER BY age ASC

请注意,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):

SELECT age
FROM users
WHERE age > 42
ORDER BY age ASC

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.

梦幻的味道 2024-12-04 16:48:27

PEBKAC:这不是 MySQL 的问题。

PEBKAC: this is not an issue with MySQL.

心作怪 2024-12-04 16:48:27

它们应该是兼容的......

我能立即想到的唯一一件事是:您在 ORDER BY 之前使用 WHERE 吗?在某些 RDBMS 实现中,查询各部分的顺序非常重要。

They are supposed to be compatible...

The only thing I can think of offhand is this: Are you using WHERE before ORDER BY? In some RDBMS implementations, the order of the parts of the query is very important.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文