Reputation: 37
I have two tables Exercises
& Workouts
. I want to fetch data from these two tables as follows:
Table structure (screenshot): table above is workout table & below that is exercises table.
I want result will be like (screenshot):
How can I get the above result from these two tables on where condition of workout_name ='Testing'
?
Upvotes: 0
Views: 1700
Reputation: 50163
Simply join
them
select w.workout_name, e.exercise_name, e.exercise_image
from Workouts w
join Exercises e on e.exercise_name = w.exercise_name
where w.workout_name = 'Testing'
Upvotes: 4
Reputation: 2011
We can also use cross apply for this-
SELECT w.workout_name, w.exercise_name, x.exercise_image
FROM Workouts w
CROSS APPLY
(
SELECT e.exercise_image FROM Exercises e WHERE e.exercise_name = w.exercise_name
) x
WHERE w.workout_name = 'Testing'
Upvotes: -1