Using same alias in two or more DIFFERENT correlated subqueries

Viewed 36

Say I have a Select list with some correlated subqueries, like:

OutputColumnAlias1 = (select min(somedate)
                      from Table1 t1
                      where t1.patientid=OuterTableAlias.patientid
                      and t1.labname='labname1')
OutputColumnAlias2 = (select min(somedate)
                      from Table1 t1
                      where t1.patientid=OuterTableAlias.patientid
                      and t1.labname='labname2')

Is it acceptable to repeat t1 in the second subquery, because it's "scope" will only be limited to the inside of that parenthetical?

Or am I unwittingly producing a bad result because, due to the first subquery, t1 will forever be defined by it's first referenced instance's WHERE clause, (etc) ?

Setting aside the badness of correlated subqueries for a moment, please advise?

0 Answers
Related