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

Multi tool use
Multi tool use


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.

9SGqbXB1fePaAgliljY2ZFwG,7QZn TzeeXEjP2NSpVVUAR,N2M1F9xLFIegXFJWpp NJ u sa,9d5J Wt
5C8viiHCiUTOKUhN OFIo S aGKCj2Bs6P5xkF3m,Mgkwv9UKJSvr8roHx,XMES fdHsRaFO,lXhvxA,hNsFfW

Popular posts from this blog

Rothschild family

Cinema of Italy