Questo contenuto non è disponibile nella lingua selezionata.

14.14. Subqueries


For databases that support subselects, Hibernate supports subqueries within queries. A subquery must be surrounded by parentheses (often by an SQL aggregate function call). Even correlated subqueries (subqueries that refer to an alias in the outer query) are allowed.
from Cat as fatcat
where fatcat.weight > (
    select avg(cat.weight) from DomesticCat cat
)
Copy to Clipboard Toggle word wrap
from DomesticCat as cat
where cat.name = some (
    select name.nickName from Name as name
)
Copy to Clipboard Toggle word wrap
from Cat as cat
where not exists (
    from Cat as mate where mate.mate = cat
)
Copy to Clipboard Toggle word wrap
from DomesticCat as cat
where cat.name not in (
    select name.nickName from Name as name
)
Copy to Clipboard Toggle word wrap
select cat.id, (select max(kit.weight) from cat.kitten kit)
from Cat as cat
Copy to Clipboard Toggle word wrap
Note that HQL subqueries can occur only in the select or where clauses.
Note that subqueries can also utilize row value constructor syntax. Refer to Section 14.19, “Row Value Constructor Syntax” for further information.
Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat