kikilis8 0 Posted March 1, 2008 Report Share Posted March 1, 2008 I want to order by second word in the field.I have a query: $rez = mysql_query("SELECT `augalas_lot`,`augalas_lt` FROM `herbs_exposition` ORDER BY `augalas_lt`"); It orders by first word of the field augalas_lt. Example of field augalas_lt:Stambiašaknis snaputisStoralapė bergenijaTamsiažiedė dedešvaTankiažiedė rūgštynėand so on.I can not separate them to different fields. How to make it sort by second word?It should look like this:Storalapė bergenijaTamsiažiedė dedešvaTankiažiedė rūgštynėStambiašaknis snaputisThank you in advance! Quote Link to post Share on other sites
Reg Edit 0 Posted March 1, 2008 Report Share Posted March 1, 2008 I want to order by second word in the field.I have a query:$rez = mysql_query("SELECT `augalas_lot`,`augalas_lt` FROM `herbs_exposition` ORDER BY `augalas_lt`"); It orders by first word of the field augalas_lt. Example of field augalas_lt:Stambiašaknis snaputisStoralapė bergenijaTamsiažiedė dedešvaTankiažiedė rūgštynėand so on.I can not separate them to different fields. How to make it sort by second word?It should look like this:Storalapė bergenijaTamsiažiedė dedešvaTankiažiedė rūgštynėStambiašaknis snaputisThank you in advance! Well, the data really should be persisted as two separate columns. However, if you insist, you can do it with a query such as the one below, but it's not a very good practice in my opinion! Also it is subject to problems if any data is inconsistent.In this example the table is categories, and the two words are in the description column: SELECT description, right( description, length( description ) - locate( ' ', description ) ) rhtextFROM categoriesORDER BY rhtext Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.