Answer the question
In order to leave comments, you need to log in
Combining two sql queries?
There are two queries to the database (almost identical):
1. makes a selection from tables with the condition that one value is greater than 0 and then sorts by one column
2. makes a selection from the same tables with the condition that one value = 0 and then sorts by another column
1.SELECT * FROM ..... WHERE quantity>0 ORDER BY quantity
2.SELECT * FROM ..... WHERE quantity=0 ORDER BY name The
question is how to combine two queries using sql or results with php
Answer the question
In order to leave comments, you need to log in
UNION already tried
if done in the form
(SELECT * FROM ..... WHERE quantity>0 ORDER BY quantity) UNION (SELECT * FROM ..... WHERE quantity=0 ORDER BY name) sorting is not saved
You can add an additional column and take it into account in sorting
SELECT tblName.* , if(quantity=0, 1,0) as x FROM tblName... ORDER BY x, quantity, name
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question