Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I Have tables
(a)
ExerciseID      ExerciseName                    MuscleTarget    SetsReps
1               FreeHand Jump Squat             Quadriceps	2 sets of 15 reps
2               Dumbbel Lunges                  Quadriceps	3 sets of 8-10
3               Dumbbel Step ups                Quadriceps	3 sets of 8-10
4               Stiff-Legged Barbell Dead Lift  Hamstrings	3 sets of 8-10 reps
5               Lying Leg Curls                 Hamstrings	3 sets of 8-10 reps
6               Leg Extensions                  Hamstrings	3 sets of 8-10 reps
7               Leg Press                       Quadriceps	3 sets of 8-12 reps


And
(b)
TrainingProgramID	ExerciseID	DayNumber
1	                7	        1
1	                8	        1
1	                9	        1
1	                10	        4
1	                11	        4
1	                12	        4


I Need Sql to select from table (a) where in table (b) DayNumber =1
Ive tried :
SQL
SELECT DISTINCT Exercise.ExerciseName, Exercise.MuscleTarget, Exercise.SetsReps, TrainingProgramExercise.DayNumber
FROM Exercise, TrainingProgramExercise
WHERE TrainingProgramExercise.DayNumber = 1
Tried a join as well but not working
Please Help


[edit]Code blocks added - OriginalGriff[/edit]
Posted
Updated 9-Sep-11 6:22am
v3
Comments
Corporal Agarn 9-Sep-11 12:21pm    
What did you try as your join?

Did you try:
SQL
SELECT DISTINCT Exercise.ExerciseName, Exercise.MuscleTarget, Exercise.SetsReps, TrainingProgramExercise.DayNumber
FROM Exercise
INNER JOIN TrainingProgramExercise 
ON Exercise.ExerciseID = TrainingProgramExercise.ExerciseID
WHERE TrainingProgramExercise.DayNumber = 1
 
Share this answer
 
Comments
Wendelius 9-Sep-11 12:26pm    
Almost identical :) my 5
SuperTeagz 9-Sep-11 12:37pm    
Thanks A lot This works..
I tried:
SELECT DISTINCT Exercise.ExerciseName, Exercise.MuscleTarget, Exercise.SetsReps, TrainingProgramExercise.DayNumber
FROM Exercise
INNER JOIN TrainingProgramExercise
ON Exercise.ExerciseID = TrainingProgramExercise.ExerciseID But had This the other way around

WHERE TrainingProgramExercise.DayNumber = 1
Wendelius 9-Sep-11 14:24pm    
BAsed on your data example I don't think you need the DISTINCT keyword. That was the difference between dj55 and my answers
Did you try something like:
SQL
SELECT Exercise.ExerciseName, 
       Exercise.MuscleTarget, 
       Exercise.SetsReps, 
       TrainingProgramExercise.DayNumber
FROM  Exercise, 
      TrainingProgramExercise
WHERE TrainingProgramExercise.DayNumber = 1
AND   Excercise.ExerciseID = TrainingProgramExercise.ExcerciseID
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900