select a.id as id,
(select name from table2 where id = a.tableid1) as id1,
(select name from table2 where id = a.tableid2) as id2
form table1 a
(select name from table2 where id = a.tableid1) as id1,
(select name from table2 where id = a.tableid2) as id2
form table1 a
select table1.id, t1.[name], t2.name
from table1
inner join table2 as t1 on table1.tableId1=t1.id
inner join table2 as t2 on table1.tableId2=t2.id
select table1.id, t1.[name], t2.name
from table1, table2 as t1, table2 as t2
where table1.tableId1=t1.id and table1.tableId2=t2.id