---
title: "hql 多对多查询 elements"
author: "kaishiba"
date: "2009-03-27T17:41:26Z"
tags: ["Blog", "SQL"]
slug: "hql-elements"
draft: false
lastmod: "2009-03-27T17:57:04Z"
id: 356293
url: "https://kaishiba.iteye.com/blog/356293"
---

可编写如下Hql 语句完成查询：

Sql代码

```
select Blog 
from Blog, Book
where Blog.author in elements(Book.authors)
	and Book.id=?
```

对应的Sql近似如下：

Sql代码

1. select  blog.*
2. from  blog, book
3. where  (blog.author  in  ( select  author.authorid
4. from  book\_author
5. where  book.id=book\_author.bookid))
6. and  book.id=?