Why can't I SELECT a parent field that doesn't have a child?
(rest_branches) is the table of restaurants.
(phone_numbers) is another table which contains the restaurants phone_numbers, and it has a field called (branc开发者_JS百科h_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?
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.
精彩评论