Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 [solved] problem in join of two tables

Author  Topic 

JoeMa
Starting Member

5 Posts

Posted - 2008-12-16 : 05:07:53
Hi there,

i don't see the forest because there are so many trees.
Maybe you can help me out?

t1 (with unique ref_id)
=======
ref_id
ref_label


t2 (ref_id occurrs 0 .. n times)
=======
ref_id
name


The result should be an alphabetical sorted list of t1.ref_label with the t2.name of the first occurrence of t1.ref_id in t2.ref_id :

ref_label name
label a name x
label b name y
label c name x


Can someone give me hint at least?

Thx in advance,

regards
joema

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-16 : 05:17:22
[code]
SELECT t1.ref_label,min(t2.name) as name
FROM t1
INNER JOIN t2
ON t1.ref_id=t2.ref_id
[/code]
Go to Top of Page

JoeMa
Starting Member

5 Posts

Posted - 2008-12-16 : 05:48:48
I have to admit that it wasn't a distinct problem

BTW, i have had to add
GROUP BY t1.ref_label
to let it work.

Nevertheless thank you very much
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-16 : 07:03:05
OOps...sorry i missed thatout during posting...glad that you spotted it and sorted it out
Go to Top of Page
   

- Advertisement -