|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have two tables. One stores all the workout entries. There can be multiple entries for the same team. This table has a teamid field. Naturally that field is the same for the teams table. I want to list all the teams but display them in order of total distance according to the first table. I can't even think of how I would start a query like this, as I have never used joins before, which I assume is what I would need in this case.
Little diagram: -Table: workouts ---Field: teamid ---Field: distance -Table: teams ---Field: id ---Field: name So I want to query the teams table, but ORDER BY the sum of all the workouts that have the same teamid. Any idea? |
|
#2
|
|||
|
|||
|
a Join would be the correct method to make this work. There are plenty of tutorials out there for joins. This would be a pretty simple query to write up. something like:
SELECT Name,Distance FROM Teams JOIN Workouts ON Workouts.teamid=Teams.id WHERE Teams.id='Some team ID number' ORDER BY workouts.distance |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Joins - Order entries by another table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|