order by two columns with same priority
i have table 开发者_开发百科, contain firstname and lastname ,
i used in my query :
ORDER BY FNAME,LNAME ASC ,
It display the records alphabetical order , and it works fine for Fname,
but it is not giving the same periority to LNAME,
my present table records :
No Fname Lname
1 Agh Asd
2 Arh AAA
3 Bcvc Vvcv
4 Akasa Dvxvx
After my query:: ORDER BY FNAME,LNAME ASC ,
No Fname Lname
1 Agh Asd
4 Akasa Dvxvx
2 Arh AAA
3 Bcvc Vvcv
But what How i want is
No Fname Lname
1 Agh Asd
2 Arh AAA
4 Akasa Dvxvx
3 Bcvc Vvcv
Yes if i change the order by lname,fname asc , then i get the expected output,
But since query giveing the high priority to the first field in the order by ,
How to over ride this,
i want equal priority in my query ,
Any good suggestion
What is equal priority? What comes first: 'Aaa Zzz' or 'Zzz Aaa' and where comes 'Mmm Mmm' between the both?
Do you want to ORDER BY
the first letters of both fname
and lname
, then by the second, etc.?
ORDER BY SUBSTRING(lname, 1, 1), SUBSTRING(fname, 1, 1), SUBSTRING(lname, 2, 1), SUBSTRING(fname, 2, 1)
精彩评论