sql - Maintaining the order by in union of two ordered by queries -
I am trying to run the question below but it seems that I am doing something wrong.
(Sample query modified for clarity only)
select name, total, rate by trade bit rate & gt; SEC Now I want to meet the union of these two questions and the result as a result. In the first line, the output should come from the first query and then output from the second query in the same sequential order, although the single was giving the actual query.
Let me know if it is still unclear, I will try to explain some more deeper level.
It's really simple: Use UNION ALL instead of < Code> unions . SELECT * (SELECT name, total, rate at the rate of trade rate at the rate> 100 ORDER by total DESC) x Select Union All * (selection name, total, rate) Trade rate of business b & lt; = 100 rate ASC rate) Y UNION reserves all coded as
Unions remove duplicates and do not guarantee the order Most databases actually sort out the output to make duplicate identification easier.
Comments
Post a Comment