Sorting Data In Mysql Based On Field Value Of a column

Posted on by By admin, in Business Intelligence, Databases | 0

This blog will teach you how to sort Data In Mysql Based On Field Value Of a column

We can sort data based on field value of a column by using ORDER BY FIELD () in mysql.

Database : world

Table name : country

If i will execute the below query :

“select distinct Continent from country” then i will get the output as :

Capture

Let say that we want to sort the data in a specific order by “Asia,Africa,North America,South America,Antarctica,Oceania,Europe”.

So in this case we can not perform simply order by because either by ascending or descending , we can not get our required output.

So let’s use the below query :

“select distinct Continent from country

order by field (Continent,’Asia’,

‘Africa’,

‘North America’,

‘South America’,

‘Antarctica’,

‘Oceania’,

‘Europe’)”

And we will get the output as required:

Capture1

Thanks,

Rupam Bhardwaj

 

 

logo

Best Open Source Business Intelligence Software Helical Insight is Here

logo

A Business Intelligence Framework

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments