开发者

Why aren't WHERE and ORDER BY compatible? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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! :)


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


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:

SELECT *
  FROM Table
 WHERE Column = Something
 ORDER
    BY ColumnId


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.


PEBKAC: this is not an issue with MySQL.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜