Deepa Kamat Deepa Kamat - 4 months ago 6
SQL Question

Sort data from MySQL table

I have a MySQL table named

camp_details
which has the following columns :

camp_id, camp_name, location, category, months , pattern


I have input fields which accepts values for
location
,
category
,
months
and
pattern
.

Based on the details provided, the table should sort according to the preferences (1:
location
, 2:
Months
, 3:
pattern
and 4:
category
).

That is, the table should display first containing
location
, next
months
and so on.

Kindly help me out in this.

Answer

just use this query

SELECT * FROM camp_details ORDER BY location , months,patter,category ;

or use DESC after column name which you want to sort in desc like

SELECT * FROM camp_details ORDER BY location , months DESC,patter,category ;