I'm trying to return the rows showing OrderIds which have duplicate values in the Notes column, ie different OrderIds which have the same value in the Notes column.
I am using this query:
SELECT
[OrderId],
[Notes]
FROM
[ord].[LineItems]
GROUP BY
OrderId, Notes
HAVING
COUNT(Notes) > 1;
The problem with the above query is that it is returning false-positives, ie rows which have duplicates in the Notes column, but they have the same OrderId (there can sometimes be duplicate rows showing the same OrderIds and Notes values, because there are different values in other fields).
I only want it to return unique OrderIds which have the duplicated values in the Notes column. How can I remove these false-positives?
Sorry this has been hard to explain, and the database I'm working with isn't well normalized.