我有两张桌子叫学生和游戏。学生Id是游戏表中的外键,每个学生可以选择多个游戏(OneToMany关系)。
这里我需要一个JPQL查询来获取学生列表和游戏列表。条件是:当我们试图寻找玩板球的学生时,返回的列表应该包含所有打板球的学生和他们选择的游戏(所有游戏,包括板球)。
例子:学生-1:足球,板球学生-2:曲棍球,板球学生-3:排球,足球学生-4:板球
预期输出:学生-1:足球,板球学生-2:曲棍球,板球学生-4:板球
发布于 2022-06-15 10:56:36
我在where子句中自己找到了添加在以下条件下的解决方案
select s from studentsEntity s left join fetch gamesEntity g
where s.studentId in (select s1.studentId from studentsEntity s1 left join gamesEntity g1 where s.studentId=s1.studentId and g1.name='Cricket')https://stackoverflow.com/questions/72626844
复制相似问题