CREATE TABLE #test1 (ID int, name1 varchar(255))
INSERT #test1 values (1, 'value1')
CREATE TABLE #test2 (ID int, name2 varchar(255))
INSERT #test2 values (1, 'value2')
CREATE TABLE #test3 (ID int, name3 varchar(255))
INSERT #test3 values (3, 'value3_01')
INSERT #test3 values (4, 'value3_02')
SELECT #test1.ID, name1, name2, name3
FROM #test1 inner join #test2 on
#test1.ID = #test2.ID left join #test3 on
#test1.ID = #test3.ID
DROP TABLE #test1
DROP TABLE #test2
DROP TABLE #test3
Hi, thanks for your input.
But when test2.id=2 the result of this query is empty. And I want then the result to be:
id1 name1 name2 name3
1 NULL NULL NULL.
I think I tried INNER JOIN test1 and test2 table, but I can have situations when test2.id doesn't match test1.id. Still I want to display ALL records of test1, but NULLS should be in test2 and test3 columns if no appropriate ids were found (test1.id=1, test2.id=2, test3.ids=3,4.....).
Why LEFT JOIN doesn't display results for table test 2 in which ids/id match id from "left" table test 1, if I join anther one table test3 in which id don't match ids from left table? Then result is: data from "left table" - this is OK, data from test3 table as NULL - this is OK, but data from test2 table should be value2, because test1.id=test2 id?????
Thanks in advance for your help.