user979331
user979331

Reputation: 11911

MySQL conflicting order by arugements

I have a query like so:

SELECT * FROM table ORDER BY home_type, home_status ASC, home_price

the home status could be either be Current, Contact or Sold, I would like the order to by home_type and if the item is sold to goto the bottom of the results, if I removed the home_type then all the items sold goto the bottom. Is there away I am have them order by home_type and if home_status is sold have it at the bottom of the results?

I guess I could do a Union but the query in question is alot bigger then the sample one I provided.

Upvotes: 1

Views: 31

Answers (1)

sgeddes
sgeddes

Reputation: 62851

If I'm understanding your question correctly, you can add home_status='Sold' to your ORDER BY clause to move all SOLD homes to the end of the list:

SELECT * 
FROM table
ORDER BY home_status='Sold', home_type, home_status, home_price

Upvotes: 3

Related Questions