This question already has answers here:
SELECT Full Row with Duplicated Data in One Column (4 answers)
Check which all records have duplicate using window function (1 answer)
Closed last month.
I want to find rows in my table where both power and price match some other row in the table.
+----+-------+-------+--------+
| id | Power | Price | Name |
+------------+-------+--------+
| 1 | 300W | $5.00 | Alpha |
| 2 | 500W | $4.00 | Kilo |
| 3 | 500W | $3.00 | Whiskey|
| 4 | 300W | $5.00 | Charlie|
| 5 | 400W | $4.00 | Oscar |
+----+-------+-------+--------+
I want the resulting table to include all columns, including the primary key, and I don't want them grouped.
+----+-------+-------+--------+
| id | Power | Price | Name |
+------------+-------+--------+
| 1 | 300W | $5.00 | Alpha |
| 4 | 300W | $5.00 | Charlie|
+----+-------+-------+--------+
What can I do to find duplicates without any of the columns or duplicate rows being eliminated?
2条答案
按热度按时间2w3rbyxf1#
If your RDBMS support window functions, you can use function
COUNT()
, then select only the records having count higher than 1 :Demo here
kkih6yb82#
Basic doubloon search :