mysql通过SQL_CALC_FOUND_ROWS删除查询

时间:2013-06-20 06:43:35

标签: mysql sql-delete

我想删除此查询返回的记录:

SELECT SQL_CALC_FOUND_ROWS tag, COUNT( tag ) AS count
FROM _tags
GROUP BY tag
HAVING count = 1
ORDER BY count DESC
LIMIT 100;

我该怎么做?

1 个答案:

答案 0 :(得分:1)

假设tag_tags'主键:

DELETE _tags.* FROM _tags
JOIN ( 
    SELECT tag FROM _tags GROUP BY tag HAVING COUNT(tag) = 1 LIMIT 100
) AS subq USING (tag)

不确定“SQL_CALC_FOUND_ROWS删除”是什么意思。如果您只想知道有多少记录符合您的条件而忽略LIMIT子句,那么您应首先运行SELECT