The problem is that you are mixing JOIN
syntax. You are using an implicit join (the comma) between T1
and T2
and then you are using explicit JOIN
syntax to join to the workcase
table.
The JOIN
syntax takes precedence over the comma so the alias is not available when you try to use it in the join condition.
If you need to use both, then you would nee to use:
select T1.ID, T2.ID
from
(
select T1.ID, T2.ID, T1.WORKCASE_ID
from task T1, task T2
where T1.STATE < 501
and T2.STATE = 501
) t
inner join workcase w
on W.ID = T1.WORKCASE_ID
where W.ID = 1683964476
This will allow the implicit join to take place in the subquery and then you will use an explicit join to the workcase
table.
Or as @APC states in the comments, this can also be written as a CROSS JOIN
:
select T1.ID, T2.ID
from task T1
cross join task T2
inner join workcase w
on W.ID = T1.WORKCASE_ID
where W.ID = 1683964476
and T1.STATE < 501
and T2.STATE = 501