开发者

Why can't I SELECT a parent field that doesn't have a child?

开发者 https://www.devze.com 2022-12-28 05:46 出处:网络
(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 res

(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.

0

精彩评论

暂无评论...
验证码 换一张
取 消