Hello I’ve been working on this all morning. I thought it was a simple self join but the self join actually returns too many rows.
Essentially I’m trying to find rows in a table where certain column values match row to row.
So if row one and three have the same column values in three specific columns then those two rows are returned.
So far I’ve tried a self-join, and a semi-join in a couple of different ways.
SELECT *
FROM ATable a, ATable b
Where a.colValue = b.colValue
and a.colValue2 = b.colValue2
This returns too many rows.
Is this query even a join? Am I on the wrong track here?
What am I missing about self joins that it returns more rows than the table itself?
ATable contains 20 rows but above query returns 36.
As Always thanks very much for any answers or hints. I learn alot just by formulating the question.
The query at the moment will return every row, because all rows are equal to themselves.
You need to restrict it so that they must be different rows.
I’m assuming you have some sort of Primary Key ID column.
Another thing you have to consider is that if you had the rows:
You’d see:
Because Row 1 is the same as Row 2. But also Row 2 is the same as Row 1.