我有一个包含三个字段的表,其中两个字段链接到同一个表中以查找值(第三个链接到第二个表)
Deployment Table
---------------------------------
INDEX, APP, DEVSERVER, PRODSERVER (was previously just SERVER)
Server Table
---------------------------------
INDEX, NAME
App Table
---------------------------------
INDEX, NAME
以前,当我在部署表中只有 SERVER 时,我正在做:
SELECT d.index, a.name as `app`, s.name as `server`
FROM deployment as `d`, app as `a`, server as `s`
WHERE d.app = a.index AND d.server = s.index
它工作正常。但是现在我想要" double dip"使用 DEVSERVER 和 PRODSERVER 进入服务器表我不是最模糊的方法。
答案 0 :(得分:0)
首先,您应该使用正确的join
语法。其次,您需要在server
表中引入第二个连接:
SELECT d.index, a.name as app, dserv.name as devserver, pserv.name as prodserver
FROM deployment d join
app a
on d.app = a.index join
server dserv
on d.devserver = dserv.index join
server pserv
on d.prodserver = pserv.index;