I'm working on converting a fairly hairy SQL query into HQL and running into some trouble. I was hoping someone else would be able to shed some light on the problem.
Here's the original SQL query:
Notice that the pl.prevID in the subquery is related to the alias pl defined in the outer query.
The purpose of this query is to generate a list of all rows in the PrevLevels table and, for each row, get the number of records in the CRev table that correspond. So, for example, I might see something like this:
Here's what I have in HQL:
I can get the outer query to work without the subquery and, likewise, I can get the subquery to work without the outer query, but if I try to execute this query as is, I get this error message:
It then goes on to spit out the query I just wrote above.
Originally posted by Craig Taylor: Can you rewrite as :
Unfortunately, no - the two queries are not the same. The query you have here (which is actually what I had started with) will leave out rows from the table PrevLevels if there are no matching records in the other tables. For my use, it's very important that, if there are no matching rows, I still get that row back with a value of 0.