I have a query that returns the following rows:
StateId, OrderId, OrderTime, PermitId
I need to return only the rows that are exact duplicates all across the board so each record must be exctly the same as the other record for it to be a duplicate. I would like to return both records. These reocrds are mixed in with a bunch of records that do not have duplicates...
Any idea?
First, identify the duplicates. Second, join back to extract these rows.
A non-aggregated (or non-window/ranking) self join forms a partial cross join and gives the square of duplicates for any set of keys. Including non-duplicates too. 1 x 1 = 1 after all.
In general, if you're just trying to see what rows have duplicate for those values...
One possibility if your database server supports subqueries: