1

Definition:

table_A                table_B
id,description         id,description,id_table_A

Column id_table_A is a foreign key to the primary key of table_A and is not mandatory.

Sample data:

table_A                 
1,some_desc_1        
2,some_desc_2

table_B
1,some_desc_1,1        
2,some_desc_2,2
3,some_desc_aaa,null
4,some_desc_bbb,null

I need to write a query that shows me all the records, including the records with the foreign key set to null. What type of join is this? I'm not able to show the records with null foreign key using an INNER JOIN.

1 Answer 1

4

Outer joins...

SELECT *
FROM
    table_B B
    LEFT OUTER JOIN
    table_A A ON B.id_table_A = A.id
;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.