0

信息

有没有一种方法可以在一个 LEFT JOIN 中两次从另一个(相同)表中检索两位信息?

试图

下面是我试图放在一起的 SQL 查询,希望能奏效。我希望你能从中看到我想要做什么。

SELECT cards.*, list.name FROM cards LEFT JOIN list ON cards.main = list.id AS main_name AND cards.enemy = list.id AS enemy_name WHERE cards.id = 1

正如您在上面看到的,我正在尝试从表中检索两个值的名称cards.main和。cards.enemylist

谢谢,有问题会尽快回复!

4

1 回答 1

0

您必须加入列表表两次:

SELECT cards.*, main_name.name, enemy_name.name 
FROM cards 
LEFT JOIN list AS main_name ON cards.main = main_name.id
LEFT JOIN list AS enemy_name ON cards.enemy = enemy_name.id
WHERE cards.id = 1
于 2013-10-27T21:54:31.777 回答