sql where subquery on id
struggling to get my head round this. i want to convert the following sql statement (converted from oracle to sql) to return all, not individual record.
select *
from table_1
where ID = @myid and MyMonth = (select max (MyMonth) from table2 where ID = @myid)
by as i said, i would like to return as a summary of everything not for the given 开发者_StackOverflowvalue of @myid.
remove the where ID parts of this returns nothing.
thanks,
Try this:
select *
from table_1 t1
where t1.MyMonth = (select max (t2.MyMonth) from table2 t2 where t1.ID = t2.ID)
精彩评论