设想:
我有一个名为片段的表,有 5 行,我有一个名为修订的表,有 15 行
我想做的是获取所有片段,它属于user_id
修订版,其中包括snippet_id
.
我有以下mysql查询:
SELECT DISTINCT * FROM "snippets"
INNER JOIN "revisions"
ON "user_id" = "1"
AND "snippet_id" = "snippets.id"
GROUP BY "snippets"."id"
ORDER BY "created_at"
那应该显示所有片段revisions.user_id = 1
。问题是,为什么我的计数不同?该查询的总结果是5,但是当我这样做时:
SELECT COUNT(distinct snippets.id) FROM "snippets"
INNER JOIN "revisions"
ON "user_id" = "1"
AND "snippet_id" = "snippets.id"
GROUP BY "snippets"."id";
结果是1 1 1 1 1