Inner Join Without Duplicates, Is It Possible?
Given these two tables Table A1 has two rows with the same value 'a' A1 a a Table A2 has two rows with primary key value A,B and they are associated with 'a' A2 PK col2 A a B
Solution 1:
You can wipe out the duplicates by using DISTINCT
selectdistinct
A1.col1,
A2.PK
from
A1
innerjoin A2
on A1.col1 = A2.col2
Solution 2:
If distinct is not restricted
SELECTDISTINCT a.*, b.pk
FROM A1 a
INNERJOIN A2 b ON (a.[test] = b.fk)
Solution 3:
There are no joining condition in the post, so we need to go for cross join. I have applied cross join and restrict the duplicate values using distinct.
Selectdistinct A1.Col1, A2.Pk
From A1 ,A2
Solution 4:
"and restrict the duplicate values using distinct." at least in Postgres 9+ DISTINCT eliminates existing duplicates but not preventing or restricting its appearing.
Solution 5:
SELECTDISTINCT A.*
FROM aTable AS A
INNER JOIN
bTable AS B USING(columnId)
Post a Comment for "Inner Join Without Duplicates, Is It Possible?"