I have the two following tables:

| ID  | Count |
| --- | ----- |
| 1   | 45    |
| 2   | 5     |
| 3   | 120   |
| 4   | 87    |
| 5   | 60    |
| 6   | 200   |
| 7   | 31    |
| SizeName | LowerLimit | UpperLimit |
| -------- | ---------- | ---------- |
| Small    | 0          | 49         |
| Medium   | 50         | 99         |
| Large    | 100        | 250        |

Basically, one table specifies an unknown number of range names and their associated integer ranges. So a count range of 0 to 49 from the person table gets a small designation. 50-99 gets 'medium' etc. I need it to be dynamic because I do not know the range names or integer values.

Can I do this in a single query or would I have to write a separate function to loop through the possibilities?

You can also use the BETWEEN operator in a JOIN like this:

SELECT a.id, a.Count, b.SizeName
FROM tableA a
JOIN tableB b ON a.id BETWEEN b.LowerLimit AND b.UpperLimit