以下查询给出了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;
答案 0 :(得分: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;