I need to connect two tables in SQL Server: Table A
has a primary key called IDTableA
(integer
field) and Table B
has a primary key IDTableB
(integer
field as well).
Table A
contains a foreign key IDTableB
whereby I want to connect both tables, this field is of type integer
and its value is 0.
My problem is that since there is no record in Table B
whose ID is 0, do not show me those records from table A with a 0 stored in the foreign key.
The relationship between both tables is: a record in Table A
may belong to one or no record in the table B. Therefore, the default value of the foreign key in table A is 0.
I tried connecting the tables with INNER JOIN
and LEFT OUTER JOIN
but it does not work and left no records show. What I can do?.
Thanks.
My SQL statement:
Select TableA.*
From TableA
inner join TableB on TableA.IdTableB = TableB.IdTableB
The Solution:
Select TableA.*
From TableA
LEFT JOIN TableB on TableA.IdTableB = TableB.IdTableB
More Info: LEFT JOIN vs. LEFT OUTER JOIN in SQL Server