不确定左连接或内连接是否最适合此查询

时间:2022-06-25 15:39:11
SELECT a.RegPropertyid,a.Bndnbr,a.account_balance,
       abs(a.account_balance) as BondBalance,b.BndregDate
INTO Jan2014ValidFin
FROM Jan2014Valid a 
LEFT JOIN  BNDtable b on a.RegPropertyid=b.propid and a.Bndnbr=b.Bndnbr
Where a.RegPropertyid is not null

 select Bnd_regDate from BND_table  
 Where Prop_id in (select regpropertyid from Jan2014ValidFin where 
 regpropertyid is not null) and BndregDate  is not null 

3 个解决方案

#1


1  

LEFT JOIN takes all the records from the first table mentioned and the records that the second mentioned table has is common with the first.

LEFT JOIN从所提到的第一个表中获取所有记录,并且第二个提到的表与第一个表中的记录相同。

INNER JOIN only takes the common terms from both.

INNER JOIN仅采用两者中的常用术语。

If TableA was A,B,C,F,G and TableB was C,D,E,

如果TableA是A,B,C,F,G和TableB是C,D,E,

TableA LEFT JOIN TableB would give you A,B,C,F,G

表A LEFT JOIN TableB会给你A,B,C,F,G

TableA INNER JOIN TableB would give you C

TableA INNER JOIN TableB会给你C

#2


0  

It depends on what you need. A left join on the first select will get you all the rows from Jan2014Valid and any matching rows from BNDtable if the propertyid column matches propid and bndnbr matches bndnbr. If it does not match you still get the row from Jan2014Valid and nulls for the columns from BNDtable.

这取决于你需要什么。第一个选择的左连接将获取Jan2014Valid中的所有行以及来自BNDtable的任何匹配行(如果propertyid列匹配propid并且bndnbr匹配bndnbr)。如果它不匹配,您仍然可以从Jan2014Valid获取行,并为BNDtable中的列获取空值。

If you make it a right join you get all the rows from BNDtable and and any matching data (columns) from Jan2014Valid table.

如果你使它成为一个正确的连接,你将获得BNDtable中的所有行以及Jan2014Valid表中的任何匹配数据(列)。

#3


0  

The Null Results that you're mentioning above aren't showing up because you wrote "is not Null", delete that and you should be good

你上面提到的Null结果没有显示,因为你写了“不是空”,删除它,你应该是好的

#1


1  

LEFT JOIN takes all the records from the first table mentioned and the records that the second mentioned table has is common with the first.

LEFT JOIN从所提到的第一个表中获取所有记录,并且第二个提到的表与第一个表中的记录相同。

INNER JOIN only takes the common terms from both.

INNER JOIN仅采用两者中的常用术语。

If TableA was A,B,C,F,G and TableB was C,D,E,

如果TableA是A,B,C,F,G和TableB是C,D,E,

TableA LEFT JOIN TableB would give you A,B,C,F,G

表A LEFT JOIN TableB会给你A,B,C,F,G

TableA INNER JOIN TableB would give you C

TableA INNER JOIN TableB会给你C

#2


0  

It depends on what you need. A left join on the first select will get you all the rows from Jan2014Valid and any matching rows from BNDtable if the propertyid column matches propid and bndnbr matches bndnbr. If it does not match you still get the row from Jan2014Valid and nulls for the columns from BNDtable.

这取决于你需要什么。第一个选择的左连接将获取Jan2014Valid中的所有行以及来自BNDtable的任何匹配行(如果propertyid列匹配propid并且bndnbr匹配bndnbr)。如果它不匹配,您仍然可以从Jan2014Valid获取行,并为BNDtable中的列获取空值。

If you make it a right join you get all the rows from BNDtable and and any matching data (columns) from Jan2014Valid table.

如果你使它成为一个正确的连接,你将获得BNDtable中的所有行以及Jan2014Valid表中的任何匹配数据(列)。

#3


0  

The Null Results that you're mentioning above aren't showing up because you wrote "is not Null", delete that and you should be good

你上面提到的Null结果没有显示,因为你写了“不是空”,删除它,你应该是好的