I have one table with two location IDs (pointa and pointb) and how far apart they are. Multiple pairs can be the same distance apart.
Example data:
pointa pointb distance
1 2 250
3 4 250
4 5 250
.....
6 8 500
10 12 500
13 17 500
I want to select one pair from each distance class (one from 250, one from 500 and so on) and join those to another table which contain attributes for that location.
If I were to write this as an algorithm, it would go:
Select one pair at random from each distance class from table distance join with table data based on distance.pointa=data.location. Then do the same for pointb such that pointb=data.location
So after the join, I end up with:
pointa pointb data_a data_b
1 2 234.5 440.2
Does anyone have ideas on how I can achieve this?
For now I am doing this using PHP (looking up attributes for a, then b, and then updating a new table. Clearly this is inefficient and I want to learn a better way to do this directly in MySQL.
tia.