mysql加入空行?

时间:2011-01-31 11:36:00

标签: sql mysql

我有这个查询

SELECT cities.city, city_date.date_avail 
FROM cities, city_date 
WHERE city_date.city_id = cities.id;

但我想查询从城市返回所有城市,即使他们没有与之关联的city_date?

1 个答案:

答案 0 :(得分:4)

参见OUTER JOINS;)(RIGHT / LEFT / FULL)

SELECT cities.city, city_date.date_avail
FROM cities
LEFT OUTER JOIN city_date ON city_date.city_id = cities.id;