3

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?

  • SELECT (some subselect) FROM t WHERE (some subselect) = 'const'?
  • View?
  • Stored Function?
  • HAVING?
  • other?
AndreKR
  • 32,613
  • 18
  • 106
  • 168

1 Answers1

6

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'
AndreKR
  • 32,613
  • 18
  • 106
  • 168
manji
  • 47,442
  • 5
  • 96
  • 103
  • but then you'd have to give up the `join on` syntax and use the dirty `where` join syntax? – Johan Apr 19 '11 at 19:27
  • Why is that? you can always use both (`s` is a table on its own). And why `where` is dirty? it's also a join (cross join) and can be useful. – manji Apr 19 '11 at 19:44