Question

I have very simple scenario

ID |NAME | DEPT_ID
1  |R K  | 1
2  |V K  | 1

DEPT_ID | LOC
1       | KA 
1       | VA

Expected output

 ID |NAME | DEPT_ID |LOC
 1  |R K  | 1       |KA
 2  |V K  | 1       |VA

But,getting

ID |NAME | DEPT_ID |LOC
1  |R K  | 1       |KA
2  |V K  | 1       |VA
1  |R K  | 1       |VA
2  |V K  | 1       |KA

I have used simple INNER JOIN. I can get my expected output ?

select ID,NAME,LOC 
from table1 
    inner join table2 on table1.dept_id=table2.dept_id
Was it helpful?

Solution

First record has dept_id of 1. There are 2 matching records for this dept_id

Second record has dept_id of 1. There are 2 matching records for this dept_id

So total 4 records in the result. It works as expected.

There is no way the server could know that KA matches R K and not V K

Conclusion: don't use non-unique field for the join.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top