personaelit
personaelit

Reputation: 1653

SQL Inner Join Returns WAY More Rows Than Expected

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.

Upvotes: 2

Views: 7009

Answers (2)

Ritsaert Hornstra
Ritsaert Hornstra

Reputation: 5111

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.

Upvotes: 1

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171371

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.

Upvotes: 6

Related Questions