![](/img/trans.png)
[英]How to join two tables in PHP - MySQL that match an ID in the second table and still display specific record in table 1?
[英]MySQL Table Join: One record, two fields, id in another table
我想聯接兩個表,產生一個結果,其中table2的第二列和第三列中的ID被table1中的相應name
值替換:
table1: id - name --------- 1 - Sam 2 - Ben 3 - Nick table2: id name1 name2 upvote downvote
1 1(id of Ben) 3(id of Nick) 150 8
因此,我的目標是加入這些表並生成:
1 - Ben - Nick - 150 - 8
我該如何實現?
需要一個簡單的Join,更多信息: MySQL Joins Manual
SELECT
table1.id,table1.name,
table2.name2,table2.upvote,
table2.downvote
FROM `table1`
INNER JOIN `table2`
ON
table2.name2 = table1.id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.