簡體   English   中英

MYSQL:我有兩個表。 我想在表 1 中使用 FK 顯示表 1 和表 2 中的數據

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM