Radek Homola
Radek Homola

Reputation: 390

MySQL show specific results on top

Now I print the results ordering only by ID, but I need to print some specific results on top.

This is my query now:

SELECT a.id,a.popis,a.datum,a.plocha,a.cena,a.podlazi,a.balkon,a.terasa,a.premiovy,a.aktivni,b.lokalita,b.lokalita_sklonena,c.dispozice,c.dispozice_sklonene,d.typ,d.typ_skloneny FROM inzerce a INNER JOIN lokality b ON a.id_obce = b.id INNER JOIN dispozice c ON a.id_dispozice = c.id INNER JOIN typy_budovy d ON a.id_typy_budovy = d.id WHERE aktivni = 0 ORDER BY a.id DESC;

And I need to print results where a.premiovy = 1 higher.

Thank you for advice.

Upvotes: 1

Views: 197

Answers (1)

Shafiqul Islam
Shafiqul Islam

Reputation: 5690

use a.premiovy order by desc and not tested, if you set order by a.premiovy = 1 then which value 1 (premiovy ) will show top then other

SELECT a.id, a.popis, a.datum, a.plocha, a.cena, a.podlazi, a.balkon, a.terasa, a.premiovy, a.aktivni, 
       b.lokalita, b.lokalita_sklonena, 
       c.dispozice, c.dispozice_sklonene, 
       d.typ, d.typ_skloneny 
FROM inzerce a 
INNER JOIN lokality b ON a.id_obce = b.id 
INNER JOIN dispozice c ON a.id_dispozice = c.id 
INNER JOIN typy_budovy d ON a.id_typy_budovy = d.id 
WHERE aktivni = 0 
ORDER BY a.premiovy = 1 DESC, 
         a.id DESC limit 5;

Upvotes: 1

Related Questions