[英]MYSQL: I have two tables. I want to show data from table 1 and table 2 using FK in table 1
我正在尝试从两个表中获取数据。 表 1 称为位置,表 2 称为餐厅。 Location 有一个名为RestaurantID (FK) 的字段,它是Restaurant 中的主键。 我想显示表Location 中“Location”列的值和“RestaurantID” (餐厅中的PK和位置中的FK)以及表餐厅中的“名称”值。 我在下面附上了 MySQL 表。
连接应该可以解决问题:
SELECT l.location, l.restaurantid, r.name
FROM location l
JOIN restaurant r ON l.restaurantid = r.restaurantid
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.