Google
Google

Reputation: 27

MYSQL - Order By price + specific first result

I use mysql, table prices with columns id, seller, price.

I want to show the results by price DESC, but I want the first result always to be the seller BOB no matter if he is more expensive.

I'm trying with:

SELECT *
FROM prices 
ORDER BY -price = BOB;

But it is not working :/

Upvotes: 0

Views: 223

Answers (4)

rdn87
rdn87

Reputation: 724

Try with this query:

SELECT * FROM prices
ORDER BY (`seller` = 'BOB') DESC, price DESC, seller 

You can re-try this query:

SELECT * FROM prices
ORDER BY (`seller` = 'BOB') DESC,(seller='James') ASC, price DESC, seller

Upvotes: 0

Google
Google

Reputation: 27

FOUND IT

order by case when name = 'BOB' then 1 else 2 end, -price DESC

Upvotes: 0

S.Pote
S.Pote

Reputation: 71

SELECT *
FROM prices
ORDER BY (`seller` = 'BOB') DESC, `seller`, 'price'

Upvotes: 1

ImDeveloping
ImDeveloping

Reputation: 101

SELECT *
FROM prices
ORDER BY (`seller` = 'BOB') DESC, `seller`

this will make it so BOB is first, you should visit w3Schools in the sql section for some help I find it to be very useful :)

Upvotes: 1

Related Questions