Embarassingly easy SQL question(s)
I am trying to write what should ostensibly, be relative easy SQL queries - yet, I cant seeem to get them to work.
Is it possible to write a query that looks something like this:
select t.name
from (select *
from mystoredproc(1,2,3) as t)
where t.name = 'foobar'
Two problems with the above query:
1) First off all, the statement above dosent work. My db engine (mySQL) complains:
ERROR 1054 (42S22): Unknown column 't.name' in 'field list'
2) I want to use the returned table t in a SELF JOIN. However, I dont want to have to call mystoredproc(...) again, because it is a VERY expensive call.
Any one knows how to fix these problems?
BTW, even though I am us开发者_高级运维ing mySQL (for now), I would prefer if any proffered SQL snippet was db agnostic (i.e. ANSI SQL)
Replace the ) as t)
with ) t
, as in
select t.name from (select * from mystoredproc(1,2,3)) t where t.name = 'foobar'
For your second problem: Feed the result from mystoredproc
into a temporary table and SELECT
from it, then you can make a self join without hassles.
精彩评论