Nhibernate简单自连接
我有一个包含这些字段的表:
ID (Primary key)
Name
Some more data fields
我想编写一个查询,给定名称将为我提供 ID 大于具有该名称的行的所有行。
(是的,我知道这个名字不是唯一的......在系统中是。)
我想要类似的东西:
select *
From SomeTable as x
WHERE x.ID> (Select ID from SomeTable as y where y.Name LIKE :param)
或者:
SELECT x
FROM SomeTable as x
JOIN SomeTable as y ON x.ID > Y.ID
WHERE Y.Name LIKE :Param
当然我想要自连接,而不是子查询。
顺便提一句。 标准也...
I have a table with these fields:
ID (Primary key)
Name
Some more data fields
I want to write a query that given a Name will give me all the rows with ID's bigger then the row with that name.
(Yes yes I know the name is not unique... in the system is.)
I want something like:
select *
From SomeTable as x
WHERE x.ID> (Select ID from SomeTable as y where y.Name LIKE :param)
or:
SELECT x
FROM SomeTable as x
JOIN SomeTable as y ON x.ID > Y.ID
WHERE Y.Name LIKE :Param
Of course I want the self join, and not the sub query.
BTW.
Criteria goes too...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将无法通过 HQL 中的联接来完成此操作。
但是这个 HQL 查询是可以的:
如果子查询可能返回多个 ID,您也可以使用
You won't be able to do it with a join in HQL.
But this HQL query is OK:
If the subselect might return several IDs, you may also use