How to compare results from sub query in main query

Viewed 23

I want to compare results from subquery with the column in main query

--this returns multiple rows 
select id, MAX(created_date) as maxdate from table 
group by id

I want to use the result set in the another query to compare date (already exist in the table) with created_date for matching id, since sub query is return multiple rows unable to use it in a sub query I get the following error More than one value was returned by a subquery..

Any help is appreciated

1 Answers

Something like this

select t1.id, t1.created_date, t2.maxdate 
from table1 as t1
join (
  select id, MAX(created_date) as maxdate from table1 
  group by id
) as t2 on 
t1.id = t2.id
Related