I have a query with a where cluse like that:
WHERE (scalar-subquery1) > (scalar-subquery2)
And it works fine. There can be any operator here instead of “greater than” (“>”) between queries.
Now I want to give a names for these queries so that I can reference them in select clause, so I tried:
SELECT q1,q2 ... WHERE (scalar-subquery1) as q1 > (scalar-subquery2) as q2
But there is syntax error reported between as q1 and > operator. Any way to work around this problem?
You can do this as a subquery:
Or as a cross join:
The third option is a variant of the first: