My DB Table field Contain value with array of data I need to sort the first value alone
Pid | Price
1 | 213,4566,112
2 | 100,452,567
3 | 653,344,6322
4 | 55,222,42,44
5 | 522
I want it to be sorted with price first value in ascending order like below
Pid | Price
4 | 55,222,42,44
2 | 100,452,567
1 | 213,4566,112
5 | 522
3 | 653,344,6322
I need a Mysql query using PHP.
You can use the following query using SUBSTRING_INDEX
:
SELECT * FROM table
ORDER BY CAST(SUBSTRING_INDEX(Price, ',', 1) AS SIGNED) ASC
Demo: http://sqlfiddle.com/#!9/3f7b7/2
Hint: You should avoid a column like
Price
with comma seperated values.
Normalize your database / tables!