SQL syntax with AS and ORDER BY in nested queries

I have a query with the following syntax:

select x.a as a, x.b as b, x.c as c
from
  (select distinct a from foo
     order by y) as x
  left join zzz....
  left join yyy...;

I want to add order byan external selection to the statement.

attaches it to the end - he does not like the syntax and puts it in front of what appears to be a valid syntax, but returns an empty result set when omitting order bynecessarily returns the results.

Any theories?

Sorry for the variable names, but they are not very important - this is more about the placement order byI'm worried about.

+3
source share
3 answers

By , Select. "", On (X = X) .

+3

y (, ) ? . , , , .

select x.a as a, x.b as b, x.c as c
from
  (select distinct a from foo) as x
  left join zzz....
  left join yyy...
order by x.a

- y, , .

0

,

select x.a as a, x.b as b, x.c as c
from
  (select distinct a from foo
     order by y) as x
  left join zzz....
  left join yyy...
order by <column list>;
-1

Source: https://habr.com/ru/post/1731871/


All Articles