Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Outer joins...

SELECT *
FROM
    table_B B
    LEFT OUTER JOIN
    table_A A ON B.id_table_A = A.id
;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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