[英]MYSQL: I have two tables. I want to show data from table 1 and table 2 using FK in table 1
I am trying to fetch data from two tables.我正在尝试从两个表中获取数据。 Table 1 is called Location and Table 2 is called Restaurant.
表 1 称为位置,表 2 称为餐厅。 Location has a field called RestaurantID (FK) which is the primary key in Restaurant .
Location 有一个名为RestaurantID (FK) 的字段,它是Restaurant 中的主键。 I want to show the value of column "Location" from table Location and the "RestaurantID" (PK in Restaurant and FK in Location) as well as " Name " value from Table Restaurant .
我想显示表Location 中“Location”列的值和“RestaurantID” (餐厅中的PK和位置中的FK)以及表餐厅中的“名称”值。 I have attached MySQL table below.
我在下面附上了 MySQL 表。
A join should do the trick:连接应该可以解决问题:
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.