Hello,
thanks for that suggestion, but the context of this query makes it very inefficient to do that.
the actual query looks something like this:
select a, b, c from someothertable where id = $1
UNION
select a, b, c from someothertable1 where id = $1
UNION
select a, b, c from someothertable2 where id = $1
UNION
select a, b, c from someothertable3 where id = $1
and so on with very MANY unions of some quite complex queries (the actual query I am working with is already more than 250 lines!). The issue is that if I try to use that sub-query method, then the query takes several minutes to complete! (i need it to return in just a couple of seconds!)
therefore, I am trying to work out how I can first evaluate that 'subquery' and then use that as argument to the main query, something like:
$2 = select name from themaintable where id = $1
select a, b, c from someothertable where id = $2
UNION
select a, b, c from someothertable1 where id = $2
UNION
select a, b, c from someothertable2 where id = $2
UNION
select a, b, c from someothertable3 where id = $2
Main Topics
Browse All Topics





by: SreejithGPosted on 2008-11-03 at 20:10:40ID: 22873515
Yes, this can be done using sub-query. Here is a sample.
select * from othertable where name = (select thename from sometable where id = $1)
Find more in help for sub-query