Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a column 1

Status
Not open for further replies.

mailtome

IS-IT--Management
Dec 10, 2004
5
IN
Hi
I have the following query
select SUBSTRING_INDEX(m.FileName, '/', -1) as ShortFileName from modifications m order by ShortFileName ASC;
The output of the query is
+------------------------+
| ShortFileName |
+------------------------+
| CTKAction.java |
| CTKView.java |
| _673.py |
| build.properties |
| eclipse.py |
+------------------------+

I have another query
Select name from dev order by name
The output of this query is
+------------------------+
| name |
+------------------------+
| A |
| a |
| b |
| C |
| c |
+------------------------+
Note the difference in the sorted output of both this query
In the first query output all the capital ones are first and then the small ones whereas in the 2nd query this is not the case.
Why the queries are behaving differently?
 
The first query is sorted in binary order, which would happen if the field was declared as BINARY, and the second query is in the default sort order, the name of which escapes me now.
 
I want the same behavior as that of 2nd query
 
If FileName is declared as BINARY, then you could use:
[tt]
SELECT
CAST(SUBSTRING_INDEX(m.FileName, '/', -1) AS CHAR)
AS ShortFileName
FROM modifications m
ORDER BY ShortFileName
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top