[英]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.