我有两张桌子Exercises
& Workouts
。我想从这两个表中获取数据,如下所示:
表格结构(截图):上面的表格是锻炼表格&下面是练习表。
我想结果会像(截图):
如何从workout_name ='Testing'
答案 0 :(得分:2)
只需join
他们
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'
答案 1 :(得分:-1)
我们也可以使用交叉申请 -
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'