-1

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

Ken White
  • 123,280
  • 14
  • 225
  • 444

1 Answers1

0

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
Ian Kenney
  • 6,376
  • 1
  • 25
  • 44