Search code examples
phpmysqlselect-query

How to make value in ascending order in the mysql?


I want this type of output to fetch task_name from database like in this format

Task 10 Task 2 Task 3 Task 5........

My Query is

 SELECT task_name, section_name, ref_student_id
 FROM scores
 WHERE ref_student_id = '".$studentid."'
    AND section_name = 'sm1'
 GROUP BY task_name

So I want to output like this..

 Task 2 Task 3 Task 5 Task 10........

Solution

  • use this

    "SELECT task_name, section_name, ref_student_id
     FROM scores
    WHERE ref_student_id = '1'
    AND section_name = 'sm1'
    GROUP BY task_name
    ORDER BY cast( SUBSTRING( task_name, 5 ) AS unsigned ) ASC"