简体   繁体   中英

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. Location has a field called RestaurantID (FK) which is the primary key in 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 . I have attached MySQL table below.

表:位置

表:餐厅

A join should do the trick:

SELECT l.location, l.restaurantid, r.name
FROM   location l
JOIN   restaurant r ON l.restaurantid = r.restaurantid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM