Subject | Getting distinct rows from a JOIN |
---|---|
Author | salisburyproject |
Post date | 2005-03-29T17:11:59Z |
Hi all,
Is there a way to use JOIN and avoid duplicate PK's from the first
table?
Example:
table 1:
ID(PK) Value
----------
1 V1
2 V2
table 2:
ID Value2
----------
1 V1
1 V2
1 V3
2 V4
2 V5
I want to be able to get the following result from the select:
1, V1, V1
2, V2, V4
, e.g. get only the first found raw from the joined table.
using:
SELECT T1.VALUE, T1.ID, T2.VALUE FROM T1 JOIN T2 ON (T1.ID=T2.ID)
ORDER BY T1.ID
will return 5 rows (as expected)
Using DISTINCT doesn't seem to alter the result..
Thanks in advance,
K.
Is there a way to use JOIN and avoid duplicate PK's from the first
table?
Example:
table 1:
ID(PK) Value
----------
1 V1
2 V2
table 2:
ID Value2
----------
1 V1
1 V2
1 V3
2 V4
2 V5
I want to be able to get the following result from the select:
1, V1, V1
2, V2, V4
, e.g. get only the first found raw from the joined table.
using:
SELECT T1.VALUE, T1.ID, T2.VALUE FROM T1 JOIN T2 ON (T1.ID=T2.ID)
ORDER BY T1.ID
will return 5 rows (as expected)
Using DISTINCT doesn't seem to alter the result..
Thanks in advance,
K.