开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜