Find IDs where another column has at least two distinct values
I have this:
SELECT DocumentID
FROM
(
SELECT DocumentID, Extension FROM Pages
GROUP BY DocumentID, Extension HAVING ( Count(1) > 2 )
) MultiplePages
GROUP BY MultiplePages.D开发者_开发知识库ocumentID Having ( Count(1) > 1 )
I am looking for a result set of Documents that have multiple pages where the pages do not share a distinct extension. This query works but I was wondering if there was a better way.
Also, I am new to Stack Overflow and I am open to suggestions on creating better titles, descriptions, or how I might have searched for this question. Thanks.
SELECT DocumentID
FROM Pages
GROUP BY DocumentID
HAVING COUNT(DISTINCT(Extension)) > 1
or
SELECT DocumentID
FROM Pages
GROUP BY DocumentID
HAVING MIN(Extension) <> MAX(Extension)
精彩评论