Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nhibernate HQL Subselect queries

Tags:

hql

nhibernate

I have the following SQL query:

select c.id
from (select id from customers) c

This query has no practical value - I simplified it greatly for the purpose of this post.

My question: is it possible have a subquery in the from clause using HQL. If not, can I perhaps query the customers first, kinda like a temp table in sql, and then use the result as the source of the next query?

thanks

like image 332
MegaByte Avatar asked Dec 23 '22 03:12

MegaByte


2 Answers

Yes, it's possible.

The query above can be written in HQL as:

select Id
from Customer
where Id in (select Id from Customer)
like image 76
Diego Mijelshon Avatar answered Jan 05 '23 16:01

Diego Mijelshon


I've run into this issue myself. Took me a while to realise that hql does not support subqueries in the from clause.

See section 14.13 in the hql documentation here.

like image 43
Jonathan Moffatt Avatar answered Jan 05 '23 15:01

Jonathan Moffatt