MySQL implementation method of multi-column ascending sort
P粉244730625
2023-08-22 18:35:13
<p>I'm trying to run this query in ascending order: </p>
<pre class="brush:php;toolbar:false;">SELECT title,project_index
FROM projectdetail
WHERE project_index BETWEEN 1 AND 6
ORDER BY title, project_index ASC;</pre>
<p>I need two columns in ascending order, but the above query only returns results for one column in <code>ASC</code> order. </p>
Ascending order is the default sorting mode for most (if not all) DBMS, so your statement is a bit strange in that regard, but anyway, you can specify the sorting mode by adding ASC or DESC on each column.
Your statement will become:
edit
As @Arvo and @Dems mentioned, you are currently sorting by title first, then by project_index if the titles are the same. If you want project_index to be sorted first, you must put it first in the ORDER BY clause.
Your statement will become:
Because ASC is the default sort order, you can omit them: