mysql - MYSQL:我有两张表。我想在表 1 中使用 FK 显示表 1 和表 2 中的数据
问题描述
我正在尝试从两个表中获取数据。表 1 称为位置,表 2 称为餐厅。Location 有一个名为RestaurantID (FK) 的字段,它是Restaurant中的主键。我想显示表Location中“Location”列的值和Table Restaurant中的“RestaurantID”(Restaurant 中的 PK 和 Location 中的 FK)以及“ Name ”值。我在下面附上了 MySQL 表。
解决方案
加入应该可以解决问题:
SELECT l.location, l.restaurantid, r.name
FROM location l
JOIN restaurant r ON l.restaurantid = r.restaurantid
推荐阅读
- mysql - 从同一列中选择多个相同的值行
- google-cloud-platform - 在 Google Cloud Build 中运行 Cypress
- python - 如何在两个数据帧之间的 np.where 中避免 NaN?
- c# - C# 反射,Reflection.TargetException,当调用 ToString(IFormatProvider)
- r - sort() 工作正常,但使用它来显示完整的排序数据框会给出不同的输出,而不是排序后的输出
- vba - 从 Access VBA 查询 Outlook 全局地址列表
- ios - 为 iOS 构建 OpenCV 静态库
- java - 从Java中的另一个类静态实例化泛型父类的子类
- javascript - 如何使用 jQuery 为数组中的每个元素插入额外的 JS 脚本?
- javascript - 是否有事件以角度检测模板元素上的类属性更改?