views:

16

answers:

1

(rest_branches) is the table of restaurants.

(phone_numbers) is another table which contains the restaurants phone_numbers, and it has a field called (branch_id) which references the restaurant id.

When I try:

SELECT * 
FROM rest_branches
NATURAL JOIN phone_numbers

I only get the restaurants which have a phone_number. What should I do to get all restaurants even if they don't have a phone number?

+1  A: 

Because that's how INNER/NATURAL joins work. If you wanted to get all restaurants, use a LEFT JOIN instead and specify the join condition.

Dave Markle
Aha, I got it, thanks a lot Dave.:)