SQL Query to show instock always but do 2 lots of ordering


SQL Query to show instock always but do 2 lots of ordering



Not sure how this would work but I can give a brief description.



I have database I want to sort but kind of sort twice in same statement.



I have products, some in stock and some out of stock, I want to always show in stock before any out of stock regardless of sorting order.
So it will sort A-Z of all in stock items first and the same query has to then show A-Z of out of stock.
Sorting in price order would show Low-High of in stock and then do the same for out of stock again in same query.



Basically, I want to be sure they can always see all the in stock items first at all times.




1 Answer
1



You can use multiple terms in the order by clause:


order by


SELECT *
FROM products
ORDER BY in_stock DESC, name ASC






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to make file upload 'Required' in Contact Form 7?

Rothschild family

amazon EC2 - How to make wp-config.php to writable?