簡體   English   中英

將一行中的兩個ID與另一張表連接起來

[英]Join two ids from one row with another table

我有兩張桌子...

固定裝置

在此處輸入圖片說明

團隊

在此處輸入圖片說明

現在,我想在表格中顯示兩個互相對戰的球隊(lteam和vteam)的名稱。 我試圖左聯接那些表,但這不起作用。 猜猜你知道為什么嗎?

SELECT * FROM fixtures 

LEFT JOIN teams as a ON fixtures.lteam = teams.id
LEFT JOIN teams as b ON fixtures.vteam = teams.id

WHERE date_ko = '2017-05-19'

謝謝你的幫助!

聯接不正確。 更改此:

LEFT JOIN teams as a ON fixtures.lteam = teams.id
LEFT JOIN teams as b ON fixtures.vteam = teams.id
                                            |

對此:

LEFT JOIN teams as a ON fixtures.lteam = a.id
LEFT JOIN teams as b ON fixtures.vteam = b.id
                                         |

您也需要在連接中使用別名

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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