I have a svn1 table:
id | date | Startdate
23 2002-12-04 2000-11-11
23 2004-08-19 2005-09-10
23 2002-09-09 2004-08-23
select id,startdate from svn1 where startdate>=(select max(date) from svn1 where id=svn1.id);
Now the problem is how can I tell the subquery to match the id with the id in the outer request. Obviously id = svn1.id does not work. Thanks!
If you have time to learn more:
This is a really simplified version of the question of what I'm really trying to do here. my actual request is something like this
select id, count(distinct archdetails.compname) from svn1,svn3,archdetails where svn1.name='ant' and svn3.name='ant' and archdetails.name='ant' and type='Bug' and svn1.revno=svn3.revno and svn3.compname=archdetails.compname and ( (startdate>=sdate and startdate<=edate) or ( sdate<=(select max(date) from svn1 where type='Bug' and id=svn1.id) and edate>=(select max(date) from svn1 where type='Bug' and id=svn1.id) ) or ( sdate>=startdate and edate<=(select max(date) from svn1 where type='Bug' and id=svn1.id) ) ) group by id LIMIT 0,40;
As you noticed, select max(date) from svn1 where type='Bug' and id=svn1.id has to be calculated many times.
Is it possible to simply calculate this once and save it with AS , and then use this variable later. The main problem is to fix id=svn1.id to correctly equate it to id in an external table.
source share