内连接结果不同 [英] Inner join result is different

查看:88
本文介绍了内连接结果不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





以下结果数是8条记录。



声明@t table( id int)

声明@t2表(id2 int)

插入@t值(1),(1),(1)

插入@t2值(1),(1),(1)

从tt上的@t t1内连接@ t2 t2选择t1.id




我认为计数应该是9个记录



请建议。



谢谢



我的尝试:



Hi,

the below result count is 8 records.

declare @t table (id int)
declare @t2 table(id2 int)
insert into @t values(1),(1),(1)
insert into @t2 values(1),(1),(1)
select t1.id from @t t1 inner join @t2 t2 on t1.id=t2.id2

I think the count should be 9 records

Please suggest.

Thanks

What I have tried:

Inner Join Result is different

推荐答案

declare @t table (id int)
declare @t2 table(id2 int)
insert into @t values(1),(1),(1)
insert into @t2 values(1),(1),(1)

select a.* from(
select row_number() over(order by id) as Sno,* from @t) as a
inner join(
select row_number() over(order by id2) as Sno,* from @t2) as b
on a.sno=b.sno


你能分享吗?他跟我查询,所以我可以检查。但是在内连接中,查询将预先形成为交叉连接,因为每个行id与下一行id相同,因此内连接将连接我们的表列id中的每个记录。
can you share the query with me so i can check.but in inner join the query will preform as cross join because every row id is same as next row id so that the inner join will join every record in our table column id.


这是不可能的

当一个不匹配时,只有一个案例是可能的
that is not possible
only one case can possible for that when one is not match


这篇关于内连接结果不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆