开发者

SQL Inner Join Returns WAY More Rows Than Expected

开发者 https://www.devze.com 2023-01-24 23:24 出处:网络
The following query returns >7000 rows when each table on开发者_StackOverflow中文版ly has 340 rows.

The following query returns >7000 rows when each table on开发者_StackOverflow中文版ly has 340 rows.

SELECT Config.Spec, TempTable.Spec FROM Confg INNER JOIN TempTable on Config.Spec = TempTable.Spec

Why would this happen? If an INNER JOIN only returns a row if there is a match in both tables then why would it return multiple rows for a match.


If there is more than one row with the same Spec value in TempTable for the same Spec value in Confg, then you will get duplicate rows, and vice versa.


Are the Spec field values non unique? This might explain why the query returns too many results; with duplicates you get get an effective cross product for those.

0

精彩评论

暂无评论...
验证码 换一张
取 消