Q&A for professional and enthusiast programmers
declare @t1 as table(id int, col1 varchar(2)); insert into @t1 select 2, 'AB' union all select 1, 'XY' union all select 5, 'PQ' union all select 4, 'AC'; declare @t2 as table(id int, col2 varchar(2)); insert into @t2 select 3, 'A1' union all select 1, 'V4' union all select 5, 'B4'; select t1.id, t1.col1, t2.col2 from @t1 t1 left join @t2 t2 on t1.id = t2.id where t1.id = t2.id;