I’m trying to get an ID from a table based on which ID has the least entries using only a single query. Is it possible to do that in just one query?
For example:
----------------------
| ID | Article_ID|
----------------------
| 1 | 7 |
----------------------
| 1 | 3 |
----------------------
| 1 | 4 |
----------------------
| 2 | 5 |
----------------------
I would want it to return “2” for the ID “2” because it only has 1 count versus ID 1 which has 3 count.
I know that I could accomplish this by first running a query to get a list of all of the IDs and then doing a loop to get each IDs count and then finally comparing them but I wanted to know if it was possible to do all of this in a single query instead.
Read the first row from the following cursor: