我有这个 sql 语句:
SELECT * FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
WHERE ( wp_term_relationships.term_taxonomy_id IN (4,3) )
AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'published')
我得到两行具有相同 ID => 预期
添加GROUP BY wp_posts.ID
会将行数减少到一
现在我想获取 SQL 查询的行数
SELECT COUNT(*) AS cnt FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
WHERE ( wp_term_relationships.term_taxonomy_id IN (4,3) )
AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'published')
GROUP BY wp_posts.ID
即使使用“GROUP BY”,我也会得到“2”而不是“1”。
从第一条语句中获取行数的正确语句是什么?