0

以下查询给了我 ERROR 1248 (42000): 每个派生表必须有自己的别名

SELECT *
FROM   post 
       LEFT JOIN post_plus 
              ON ( post.id = post_plus.news_id ) 
       LEFT JOIN (SELECT DISTINCT c1.postid FROM post_category c1 JOIN post_category c2 ON c1.postid = c2.postid WHERE  c1.categoryid IN ( 130, 3, 4, 5 ) AND c2.categoryid = 73 ) 
       where approve = 1 
ORDER  BY fixed DESC, 
          date DESC 
LIMIT  0, 7; 

我试过的

    SELECT a.*
    (FROM   post 
...
    LIMIT  0, 7)a; 
4

1 回答 1

3

派生表需要一个别名,并且您也缺少一个连接条件。

SELECT *
FROM   post
       LEFT JOIN post_plus
         ON ( post.id = post_plus.news_id )
       LEFT JOIN (SELECT DISTINCT c1.postid
                  FROM   post_category c1
                         JOIN post_category c2
                           ON c1.postid = c2.postid
                  WHERE  c1.categoryid IN ( 130, 3, 4, 5 )
                         AND c2.categoryid = 73) post_category /*<-- Missing Alias*/
         ON ( post_category.postid = post.id ) /*<-- Missing Join Condition*/
WHERE  approve = 1
ORDER  BY fixed DESC,
          date DESC     
LIMIT  0, 7;           
于 2013-09-08T20:25:08.900 回答