我有一个MySQL问题。它工作得很好,但速度非常慢。跑步需要30秒。
SELECT t.Id, Subject, k.info
FROM tip t
LEFT JOIN comments k ON t.Id = k.Tipid
WHERE event = 1
AND k.Id
IN (
SELECT Max(Id) FROM comments GROUP BY Tipid
)
如果我只运行子查询(
SELECT Max(Id) FROM comments GROUP BY Tipid
),则运行大约需要0.02秒。子查询有问题。你有什么想法吗?
最佳答案
如果选择max(id),则不需要分组
SELECT t.Id, Subject, k.info
FROM tip t
LEFT JOIN comments k ON t.Id = k.Tipid
WHERE event = 1
AND k.Id in (select Max(Id) from comments)
关于mysql - MySQL子查询很慢,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14850580/