Reputation: 530
I want to use the same subquery in from and where clause. Tried following two approaches, but getting same error in both cases at different places in the query.
QUERY 1:
select * from (subquery1) as t_feature where id = (select MAX(id) from t_feature);
QUERY 2:
select * from t_feature where id = (select MAX(id) from (subquery1) as t_feature);
ERROR:
ERROR: relation "t_feature" does not exist
For temporary soultion, I have created a view for the subquery, and used that in place of the subquery. But I do not want to create views for this case.
Upvotes: 0
Views: 209
Reputation:
Use a common table expression:
with t_feature as (
...
)
select *
from t_feature
where id = (select MAX(id) from t_feature);
Upvotes: 1