user1673032
user1673032

Reputation: 11

How to order by Special character in mysql

my column value is

firstname
===============
mufi**alam
lam**slam
zia**busa

i want to oreder by after star in value. how we can usewhich query of mySql

Upvotes: 1

Views: 488

Answers (3)

Try this

SELECT first_name FROM persons ORDER BY SUBSTRING_INDEX(first_name, '*', -1) [desc,asc];

here desc means descending order, asc means ascending order.

Upvotes: 0

Sumit Bijvani
Sumit Bijvani

Reputation: 8179

Try this query

SELECT firstname FROM persons
ORDER BY SUBSTRING_INDEX(firstname, '*', -1);

Output

|  FIRSTNAME |
--------------
| mufi**alam |
|  zia**busa |
|  lam**slam |

SQLFiddle Demo

Upvotes: 0

echo_Me
echo_Me

Reputation: 37243

try this

   SELECT SUBSTRING_INDEX(firstname, '*', -1) AS foo FROM Table1
   order by foo;

DEMO HERE

or this demo if you want show the firstname column

demo

or this without foo column , just order by after *.

  SELECT firstname  FROM Table1
  order by SUBSTRING_INDEX(firstname, '*', -1);

demo

Upvotes: 1

Related Questions