bigint id 上的 T-SQL LEFT JOIN 仅返回右表中低于 101 的 id
我在 Sql Server 2008 上有两个表。 ownership
包含 3 个字段,case
包含另外 3 个字段,我需要将这两个字段加入 ID 字段(bigint)。
出于测试目的,我仅使用每个表中的一个字段。该字段为 bigint,值范围为 1 到 170(目前)。
我的查询是:
SELECT DISTINCT
ownership.fCase,
case.id
FROM
ownership LEFT JOIN case ON (case.id=ownership.fCase)
WHERE
ownership.dUser='demo'
这预计会返回 4 行,两列上的值相同。问题是,对于 fCase = 140,右表的最后一行为空。这是唯一高于 100 的值。
如果我在没有 WHERE 子句的情况下运行查询,它将显示左表中的所有行,但右表上的值仅当低于 101 时才会出现,否则显示 null。
有人可以帮助我吗,我做错了什么还是这是一个限制或错误?
I have two tables on a Sql Server 2008.ownership
with 3 fields and case
with another 3 fields I need to join both on the ID field (bigint).
For testing purposes I'm only using one field from each table. This field is bigint and has values from 1 to 170 (for now).
My query is:
SELECT DISTINCT
ownership.fCase,
case.id
FROM
ownership LEFT JOIN case ON (case.id=ownership.fCase)
WHERE
ownership.dUser='demo'
This was expected to return 4 rows with the same values on both columns. Problem is that the last row of the right table comes as null for the fCase = 140. This is the only value above 100.
If I run the query without the WHERE clause it show all rows on the left table but the values on the right only apear if below 101 otherwise shows null.
Can someone help me, am I doing something wrong or is this a limitation or a bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大小写也是一个动词,所以可能会混淆。在 [] 中尝试您的表名和列名。 EG [case].[id] = [所有权].[fCase]。您是否喜欢仔细检查以确保 [case].[id] 和 [ownership].[fCase] 都是 bigint。如果您当前的值是 1-170 那么为什么是 bigint (9,223,372,036,854,775,807)?该列接受空值吗?
Case is also a verb so it may be getting confused. Try your table and column names in []. E.G. [case].[id] = [ownership].[fCase]. Are you like double check sure that [case].[id] and [ownership].[fCase] are both bigint. If your current values are 1-170 then why bigint (9,223,372,036,854,775,807)? Does that column accept nulls?