Jump to content

ORDER BY second word in the field


Recommended Posts

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!

Link to post
Share on other sites
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

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...