有没有更好的方法来优化此查询?

时间:2012-09-20 21:09:05

标签: mysql join left-join

如何优化此查询?如果您需要表结构,请告诉我,但这是作为Vanilla论坛的自定义插件

完成的
SELECT
    G.*
FROM
    (
        SELECT
            D.DiscussionID,
            A. NAME AS Category,
            D. NAME,
            U. NAME AS USER,
            D.CountComments,
            IFNULL(
                MAX(C.DateInserted),
                D.DateInserted
            ) AS Updated
        FROM
            GDN_Discussion AS D
        LEFT OUTER JOIN GDN_Comment AS C ON D.DiscussionID = C.DiscussionID
        INNER JOIN GDN_Category AS A ON A.CategoryID = D.CategoryID
        LEFT OUTER JOIN GDN_User AS U ON U.UserID = D.InsertUserID
        WHERE
            A.CategoryID = '626'
        GROUP BY
            D.DiscussionID
    ) AS G
ORDER BY
    G.Updated DESC
LIMIT 0, 10

0 个答案:

没有答案