Mysql Multiple Column Asc Order
Solution 1:
Ascending order is the default for most (if not all) DBMS's so your statement is kind of weird in that respect but nevertheless, you can specify an order for each individual column by adding the specifier ASC or DESC to it.
Your statement then would become
SELECT title
, project_index
FROM projectdetail
WHERE project_index BETWEEN1AND6ORDERBY
title ASC
, project_index ASCEdit
As been mentioned by @Arvo & @Dems, currently you are sorting first on title and for identical titles on project_index. If you want your project_index sorted first, you have to place it first in the ORDER BY clause.
Your statement then becomes
SELECT title
, project_index
FROM projectdetail
WHERE project_index BETWEEN1AND6ORDERBY
project_index ASC
, title ASCand because ASC is the default sort order, you can omit them alltogether
SELECT title
, project_index
FROM projectdetail
WHERE project_index BETWEEN1AND6ORDERBY
project_index
, title
Solution 2:
If you are using mysql, check this out.
As they say there, you can use SELECT * FROM t1 ORDER BY key_part1 DESC, key_part2 ASC;
Solution 3:
ORDER BY title ASC, project_index ASC;
SELECT title,project_index
FROM projectdetail
WHERE project_index BETWEEN1AND6ORDERBY title ASC, project_index ASC;
AND you can add more columns like ORDER BY col1 ASC, col2 ASC, col3 DESC;
Solution 4:
Try this:
SELECT title, project_index
FROM projectdetail
WHERE project_index BETWEEN1AND6ORDERBY project_index, title;
Solution 5:
You try to sort both columns in ascending order. In mysql, you can use multiple order in a query. But the preference for the order by is very important here. First one get the most preference and next one get second preference. That means, Your query is
SELECT title,project_index FROM projectdetail
WHERE project_index BETWEEN1AND6ORDERBY title, project_index ASC;
Where, order by title got first preference. The mysql will order the 'title' column in ascending order at first and display the result. Then only it will order 'project_index' column. So you cann't get answer as you want.
Post a Comment for "Mysql Multiple Column Asc Order"