如何返回与另一个表不匹配的行?
我正在使用 fluid nhibernate 和 nhibernate 3.1,我想知道如何进行查询以返回与另一个表中不匹配的结果。
假设我有表 A 中的 5 条记录和表 B 中的 3 条记录。现在,表 A 中的 3 个与表 B 中的 3 个匹配。
所以我想返回这两行,因为它们不在 TableB 中。我看到的所有连接似乎都在寻找匹配项并返回匹配项。我想基本上返回差异。
如果说我有表 A 中的 5 条记录和表 B 中的 100 条记录,但表 A 的记录均不与表 B 中的任何记录匹配,我想返回表 A 的所有记录。
I am using fluent nhibernate and nhibernate 3.1 and I am wondering how do I make a query to return results that don't match in another table.
Say I have 5 records from tableA and 3 records in tableB. Now 3 from TableA match the 3 from TableB.
So I want to return these 2 rows back as they where not in TableB. All the joins that I seen seem to look for matches and return the matches. I want to basically return the differences.
if say I had 5 records from tableA and 100 in TableB but none of TableA's records matched any in TableB I want to return all of tableA's records.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我不确定我是否回答了正确的问题,你的描述似乎有点模糊...
有几种方法可以解决这个问题...
我想最简单和最容易的方法是使用 SQL 查询:
string sqlQuery = "Select * from TABLENAMEA A where a.field not in (select b.field from TABLENAMEB b)"
results = (OBJECT) session.ExecuteSQL(sqlQuery);
请记住,我是凭记忆这样做的,我知道存在执行此操作的设施...并且可能不会花费您超过一两分钟的时间来弄清楚...
Well I'm not sure that I'm answering the right question, your description seems a little fuzzy...
There's a couple of ways to go about this...
I guess the simplest and easiest way would be to use a SQL query:
string sqlQuery = "Select * from TABLENAMEA A where a.field not in (select b.field from TABLENAMEB b)"
results = (OBJECT) session.ExecuteSQL(sqlQuery);
Bear in mind that I'm doing that from memory, I know the facilities to do this exist... And probably won't take you more then a minute or two to figure out...