vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I am sure that this has been asked - but in searching through google and lists for about an hour - hopefully someone will indulge me a repeat question here. I have a query that selects a list of results, ordering them by the status field. However, I want to further sort that by the type of status, that is: Undefined Ready for Review Top Priority Priority Completed Etc... Every sort that I try, of course, sorts alphabetically. Is there a way to define how the sort function works in the order by? I know that I could do this in PHP after populating the results into an array, but that is (in my opinion) an unnecessary step that could be handled at the database query.... Thanks! Sample query: Select * from development order by status -- Cheers Mike Morton ************************************************** ** * * Tel: 905-465-1263 * Email: mike@webtraxx.com * ************************************************** ** |
| |||
| [snip] I have a query that selects a list of results, ordering them by the status field. However, I want to further sort that by the type of status, that is: Undefined Ready for Review Top Priority Priority Completed Etc... Every sort that I try, of course, sorts alphabetically. Is there a way to define how the sort function works in the order by? [/snip] You can specify ORDER BY foo DESC or ASC and you can do multiple ORDER BY's SELECT * FROM table ORDER BY foo, bar |
| |||
| Hi, You could use a case statement to implicitly convert your column to everything you want: select status, case when status = 'undefined' then 4 when status = 'Top Priority' then 1 ... End as ord_status from development order by ord_status Bye Geoffroy -----Message d'origine----- De*: Mike Morton [mailto:mike@webtraxx.com] Envoyé*: mardi 5 juin 2007 23:26 À*: mysql@lists.mysql.com Objet*: Sorting by a list of possible results in a column.... I am sure that this has been asked - but in searching through google and lists for about an hour - hopefully someone will indulge me a repeat question here. I have a query that selects a list of results, ordering them by the status field. However, I want to further sort that by the type of status, that is: Undefined Ready for Review Top Priority Priority Completed Etc... Every sort that I try, of course, sorts alphabetically. Is there a way to define how the sort function works in the order by? I know that I could do this in PHP after populating the results into an array, but that is (in my opinion) an unnecessary step that could be handled at the database query.... Thanks! Sample query: Select * from development order by status -- Cheers Mike Morton ************************************************** ** * * Tel: 905-465-1263 * Email: mike@webtraxx.com * ************************************************** ** -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=g...y@cogniaux.com |
| ||||
| Mike >I have a query that selects a list of results, ordering them by the status >field. However, I want to further sort that by the type of status, that is: >Undefined >Ready for Review >Top Priority >Priority >Completed ORDER BY FIELD( columnname, 'Undefined', 'Ready for Review', ... ) PB Mike Morton wrote: > I am sure that this has been asked - but in searching through google and > lists for about an hour - hopefully someone will indulge me a repeat > question here. > > I have a query that selects a list of results, ordering them by the status > field. However, I want to further sort that by the type of status, that is: > > Undefined > Ready for Review > Top Priority > Priority > Completed > Etc... > > Every sort that I try, of course, sorts alphabetically. Is there a way to > define how the sort function works in the order by? > > I know that I could do this in PHP after populating the results into an > array, but that is (in my opinion) an unnecessary step that could be handled > at the database query.... > > Thanks! > > Sample query: > Select * from development order by status > > > |