Sorting Issues

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 排序问题

| username: Running

Cannot return data in descending order by the agreed month.

| username: h5n1 | Original post link

Move the “order by” to after “t”.

| username: tidb菜鸟一只 | Original post link

You sorted it inside, but it came out unsorted, so it was sorted for nothing…

| username: Jolyne | Original post link

The SQL is not written like this. If you want to sort the results of the subquery, you should put the order by at the end.

| username: TiDBer_小阿飞 | Original post link

Inner layer sorting? The outer select doesn’t recognize it.

| username: Running | Original post link

In MySQL, you can play it this way. If the outer layer is not sorted, it will default to sorting based on memory. We are using a BI system, and the BI will default to adding a layer, which we cannot control.

| username: Running | Original post link

Additionally, in version 7.0, it is also possible to sort by memory.

| username: TiDBer_小阿飞 | Original post link

What is the character type of the usru_month field?

| username: zhanggame1 | Original post link

TiDB is not MySQL. If ORDER BY is not placed at the end, all results can be considered unordered.

| username: 像风一样的男子 | Original post link

Try adding a LIMIT to your subquery. This might prevent the ORDER BY from being ignored.

| username: 人如其名 | Original post link

What version? What is the execution plan? How can you just throw out a question without providing any details? How is anyone supposed to answer that?

| username: andone | Original post link

Just put the order by on the outside.

| username: kelvin | Original post link

The correct way is to put “order by” at the end.

| username: Running | Original post link

Recently, after rolling back from 7.3 to 7.1, the relevant information was verified:
This should be related to the default collation. In 7.3, you need to add a limit in the subquery, so the outer layer does not need to sort again; in 7.1.2, there is no need to add a limit, the data is displayed as it is sorted in memory.

| username: swino | Original post link

ORDER BY needs to be at the end of the query statement.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.