10

I have three tables: class, student, and teacher

table class
{
    class_id(PK)
}

table student
{
    student_id(PK)
    class_id(PK+FK)
}

table teacher
{
    teacher_id(PK)
    class_id(PK+FK)
}

I have a query in SQL, which works fine.

SELECT data.class_id, count(data.class_id) AS count
FROM ((SELECT class_id FROM student)
        union all
        (SELECT class_id FROM teacher)) AS data
GROUP BY data.user_id
ORDER BY count desc

The query contains sub query in the from clause and union operation. I unable to convert it to the HQL.

please give me the efficient HQL query from the above SQL query.

Roman C
  • 49,761
  • 33
  • 66
  • 176
user2000
  • 137
  • 1
  • 9

2 Answers2

8

Unfortunately HQL does not support UNION queries. Two alternative strategies to solve your problem are:

Community
  • 1
  • 1
Anthony Accioly
  • 21,918
  • 9
  • 70
  • 118
7

You cannot place a subquery at the from clause in HQL. Only select or where clauses.

Roman C
  • 49,761
  • 33
  • 66
  • 176