Reusing a subquery from Select Expression in the WHERE clause

Of course write

impossible
SELECT (some subselect) AS blah FROM t WHERE blah = 'const' 

What is the best way to do this?

  • SELECT (some subselect) FROM t WHERE (some subselect) = 'const' ?
  • View?
  • Saved function?
  • HAVING?
  • other?
+3
source share
1 answer

you can move (some subselect) as a table in FROM :

 SELECT s.blah FROM t, (some subselect) s WHERE t.id = s.id AND s.blah = 'const' 
+6
source

All Articles