Mysql 仅为每行的一个单元格从另一个表中获取值
假设我有桌子Mysql 仅为每行的一个单元格从另一个表中获取值,mysql,sql,Mysql,Sql,假设我有桌子 ### Table 1 ### id | id(foreign key from Table 2) | id(foreign key from Table 3) ------------ 1 1 1 2 2 1 ### Table 2 ### id | title | id(foreign key from Table 3) ----------------- 1 Happy 1 2 Halloween 2 ### Table
### Table 1 ###
id | id(foreign key from Table 2) | id(foreign key from Table 3)
------------
1 1 1
2 2 1
### Table 2 ###
id | title | id(foreign key from Table 3)
-----------------
1 Happy 1
2 Halloween 2
### Table 3 ###
id | name
1 | John
2 | Doe
### Expected Result ###
`Table 2`.`id` | `Table 2`.title | `Table 3`.name
-----------------------------------------------------
1 Happy John
2 Halloween Doe
另外两个我都答对了,但我不知道如何从表3中得到名字
选择表2
id
,表2
,标题
,表2
。从表2
,表3
其中表1
id
(表2的外来项)=表2
id
因为现在只有约翰在看
### Current Result###
`Table 2`.`id` | `Table 2`.title | `Table 3`.name
-----------------------------------------------------
1 Happy John
其中id2/id3表示“表2/表3中的外键”。您希望看到什么结果?
SELECT `Table 2`.`id2`, `Table 2`.`title`, `Table 3`.`name`
FROM `Table 2`
JOIN `Table 3` ON `Table 2`.`id3` = `Table 3`.`id3`