1

I have MySQL table with similar data

France  - 1
Germany - 2
Italy   - 3
France  - 5
Germany - 3
France  - 2

I want to select everything (It's easy SELECT * FROM table), but I want to sort data the way that France will be always first, so outcome should be:

France  - 1
France  - 5
France  - 2
Germany - 2
Germany - 3
Italy   - 3

Can this be done on MySQL side or I should do this inside foreach statement?

Thank you.

2 Answers 2

3

Either

select * from your_table
order by country <> 'France',
         country

or

select * from your_table
order by case when country = 'France'
              then 1
              else 2
         end,
         country
Sign up to request clarification or add additional context in comments.

2 Comments

I just found "select * from table order by field(county, 'FRANCE'), variety" this is better or...?
Whatever works for you is fine. There are acually even more possibilities to do it
0

you can also do this by

$result=mysql_query("select * from   
   countrydata order by country ASC");
while($row=mysql_fetch_row($result)){
    $id=$row[0];
    $name=$row[1];
    echo $name."&nbsp;".$id."<br>";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.