SQL JOIN语句的语法错误

时间:2013-06-11 09:12:57

标签: java mysql hibernate join hql

我正在尝试创建一个HQL查询,以便将select的结果与另一个表连接起来。我目前所拥有的是

SELECT e FROM Experience e JOIN (SELECT f FROM Follow f WHERE f.username = :username AND f.contentType = :contentType) AS A ON (e.experienceId = A.contentId);

目前有效的SQL等价物是

SELECT t_experiences.* FROM t_experiences JOIN (SELECT * FROM t_follows WHERE t_follows.username = :username AND t_follows.content_type = :contentType) AS A ON (t_experiences.experience_id = A.content_id);

t_experiences.experience_id等同于Experience.experienceId等等.HQL中的当前错误位于第一个(,错误为unexpected token: (

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

为什么不试试这个:

SELECT e.experienceId FROM Experience e, Follow f WHERE f.username = :username AND f.contentType = :contentType AND (e.experienceId = f.contentId);

我认为这应该适合你。

Note: Replace e.experienceId by parameters which you want.