AndreKR
AndreKR

Reputation: 33678

Reuse Subquery from Select Expression in WHERE-Clause

Of course it isn't possible to write

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

What is the best way to do this?

Upvotes: 3

Views: 2980

Answers (1)

manji
manji

Reputation: 47978

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

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

Upvotes: 6

Related Questions