0
SELECT t1.* FROM HOSTS AS t1
WHERE
t1.BOSS = 'BRUCE'
OR ( t1.BOSS_TYPE = 'manager'
 AND t1.BOSS_ID = 'BRUCE' )
OR t1.BOSS IN ( SELECT t2.STORES FROM
  FOLLOW_STORES AS t2 
 WHERE t2.BOSSES = 'BRUCE' )

上面的查询效果很好,但我想添加一个 JOIN 来获取额外的信息

我想添加这个 JOIN 但我无法让它工作。我一定是把它插错了地方。

 JOIN MANAGER_POSTS AS t3 ON ( t1.POSTER_ID = t3.POSTER_ID
    AND t1.SUBMISSION_TYPE =  'post' )

添加连接以获取此额外信息的正确方法是什么

4

2 回答 2

1

在这里试试这个:

SELECT  t1.* , t3.*
FROM    HOSTS AS t1 
            INNER JOIN MANAGER_POSTS AS t3 
                ON ( t1.POSTER_ID = t3.POSTER_ID AND 
                     t1.SUBMISSION_TYPE =  'post' )
WHERE   t1.BOSS = 'BRUCE' 
        OR (t1.BOSS_TYPE = 'manager' AND t1.BOSS_ID = 'BRUCE' )
        OR t1.BOSS IN   ( 
                            SELECT t2.STORES 
                            FROM FOLLOW_STORES AS t2 
                            WHERE t2.BOSSES = 'BRUCE' 
                        )
于 2012-07-30T10:16:38.847 回答
0

您需要在您的之后和之前添加您的JOIN子句FROM HostsWHERE

SELECT t1.* 
FROM HOSTS AS t1
INNER JOIN MANAGER_POSTS AS t3 
    ON ( t1.POSTER_ID = t3.POSTER_ID
    AND t1.SUBMISSION_TYPE =  'post' )
WHERE t1.BOSS = 'BRUCE'
    OR ( t1.BOSS_TYPE = 'manager'
          AND t1.BOSS_ID = 'BRUCE' )
    OR t1.BOSS IN ( SELECT t2.STORES 
                    FROM FOLLOW_STORES AS t2 
                    WHERE t2.BOSSES = 'BRUCE' )
于 2012-07-30T10:16:27.947 回答