So, I’m completely new to mySql and just trying to self teach it.
Example table structure:
tblA
-----
PK: userId
tblB
-----
PK: workoutId
FK: userId
tblC
-----
PK: cardioId
FK: workoutID
table C has a distance field.
Currently when I run SELECT SUM(distance) FROM tblC I get the correct amount, however, when I only want to select the sum of distance for the particular user, I tried:
SELECT SUM(distance) FROM tblC JOIN tblB ON (tblC.workoutId AND tblB.workoutId) WHERE userId = '1'
This gives a me a rediculously higher value than before. Where am I going wrong?
1 Answer