我有2张桌子,汽车和经销商。
CARS: id, make, model, year, dealership_id
DEALERSHIPS: id, name, address
汽车有brokerhip_id属性,但没有经销商名称。如果cars.dealership_id和dealership.id匹配,如何在加入表时添加经销商名称?
这是我到目前为止所拥有的:
SELECT cars.make, cars.model, cars.year
FROM cars
JOIN dealerships cars ON cars.dealership_id = dealership.id
答案 0 :(得分:1)
这个怎么样?
SELECT cars.make, cars.model, cars.year, dealerships.name
FROM cars
JOIN dealerships ON cars.dealership_id = dealerships.id