I have a table with a lot of records with duplicate fields. I want the most common of each of these duplicates.
So, if there is data in my table as shown below:
ID Field1 Field2 1 A 10 2 A 12 3 B 5 4 A 10 5 B 5 6 A 10 7 B 8 8 B 5 9 A 10
I can choose a separate one and get the quantity:
select distinct Field1, Field2, count(Field1) from Table group by Field1, Field2 order by Field1, count(Field1) desc
And it will give me
Field1 Field2 Count A 10 4 A 12 1 B 5 3 B 8 1
However, I only need the entries for each field 1 that have the highest score. I fought rank () over sections and subqueries, but did not find the correct syntax for using two fields for uniqueness and selecting the top record in a row. I searched, and Iβm sure it was asked, but I canβt find it.
I want to get the following
Field1 Field2 (optional) Count A 10 4 B 5 3
The goal is to look at a table with a small amount of incorrect data (the relationship between field 1 and field 2) and determine what it MUST be based on what it usually represents. I donβt know how many bad entries there are, so removing Count below a certain threshold will work, but it seems a bit shabby.
If this is better, I can create a temp table to insert my various values ββand then select from there, but it doesn't seem like it is necessary.