Raphaël
Raphaël

Reputation: 1141

Mysql sort results without exclude others results

I have a list of localized results by country. I would first like to get the result of the Effective Country X first and then the others in the same. Is that possible?

If I set a where "anno_country" = 1 ... it excludes the results of other countries. I would like something like "order by country = 3" ...

Currently, this is my MySQL query :

SELECT DISTINCT * 
FROM (`annonce`) 
JOIN possede USING (`anno_id`) 
JOIN annonceur USING (`ann_id`) 
JOIN lang_pays USING (`pays_id`) 
JOIN cat_lang USING (`cat_id`) 
WHERE 
    `cat_id` IN ('4', '9', '5', '426', '6', '435', '7', '3', '8', '2') 
    AND 
    `anno_active` = 1 
    AND 
    `anno_mode` = 1 
    AND 
    `cat_lang`.`lang_id` = '3' 
    AND 
    `lang_pays`.`lang_id` = '3' 
ORDER BY `anno_id` desc

Do you have an idea ?

Upvotes: 0

Views: 457

Answers (2)

sel
sel

Reputation: 4957

SELECT * FROMyourtableORDER BY (country= 'X') DESC,country

This will order by country x first then other countries.

Upvotes: 1

fthiella
fthiella

Reputation: 49079

You can use this:

ORDER BY (country != 3), anno_id DESC

this will show rows with country = 3 at the top, ordered by anno_id desc, and then all rows with country!=3 at the bottom, ordered by anno_id desc.

Upvotes: 1

Related Questions