SQL Inner Join Returns WAY More Rows Than Expected

僤鯓⒐⒋嵵緔 提交于 2019-12-31 03:47:12

问题


The following query returns >7000 rows when each table only 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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4185891/sql-inner-join-returns-way-more-rows-than-expected

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!