declare @VAR int; set @VAR = (select max(id) from table); select * from table2 where id = @VAR