I would like to select the X most common pairs per group in a table. Let's consider the following table:
+-------------+-----------+
| identifier  |    city   |
+-------------+-----------+
| AB          |  Seattle  |
| AC          |  Seattle  |
| AC          |  Seattle  |
| AB          |  Seattle  |
| AD          |  Seattle  |
| AB          |  Chicago  |
| AB          |  Chicago  |
| AD          |  Chicago  |
| AD          |  Chicago  |
| BC          |  Chicago  |
+-------------+-----------+
- Seattle, AB occurs 2x
- Seattle, AC occurs 2x
- Seattle, AD occurs 1x
- Chicago, AB occurs 2x
- Chicago, AD occurs 2x
- Chicago, BC occurs 1x
If I would like to select the 2 most commons per city, the result should be:
+-------------+-----------+
| identifier  |    city   |
+-------------+-----------+
| AB          |  Seattle  |
| AC          |  Seattle  |
| AB          |  Chicago  |
| AD          |  Chicago  |
+-------------+-----------+
Any help is appreciated. Thanks, Benni
 
     
    