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
 Transact-SQL (2000)
 Join

Author  Topic 

velliraj
Yak Posting Veteran

59 Posts

Posted - 2009-11-08 : 12:35:19
Hi

I have two tables eg:
Table a

Empid salary
1 5000
1 2000
1 3000

table b

empid pone
1 12345
1 3456

i ned to get output as

empid salary phone
1 5000 12345
1 2000 3456
1 3000 -


please help

wheni try with left join it is returning the multiples. plz help.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-08 : 13:05:35
Sorry but that makes no sense.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-09 : 02:24:38
quote:
Originally posted by velliraj

Hi

I have two tables eg:
Table a

Empid salary
1 5000
1 2000
1 3000

table b

empid pone
1 12345
1 3456

i ned to get output as

empid salary phone
1 5000 12345
1 2000 3456
1 3000 -


please help

wheni try with left join it is returning the multiples. plz help.



Do you have any other unique keys in the table?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-11-09 : 03:14:55
Hi velliraj

Its not make sense. can you please check the table if u have any other unique keys.

Try this...its working(2005/2008)...but not suggested.

SELECT A.ID, A.NUM , B.NUM FROM
(

SELECT DENSE_RANK() OVER (PARTITION BY ID ORDER BY NUM DESC)as ROW_ID,* FROM #tempA ) as A
LEFT OUTER JOIN
(
SELECT DENSE_RANK() OVER (PARTITION BY ID ORDER BY NUM DESC)as ROW_ID,* FROM #tempB ) as B
ON A.ROW_ID = B.ROW_ID









-------------------------
R...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-09 : 04:33:01
quote:
Originally posted by rajdaksha

Hi velliraj

Its not make sense. can you please check the table if u have any other unique keys.

Try this...its working(2005/2008)...but not suggested.

SELECT A.ID, A.NUM , B.NUM FROM
(

SELECT DENSE_RANK() OVER (PARTITION BY ID ORDER BY NUM DESC)as ROW_ID,* FROM #tempA ) as A
LEFT OUTER JOIN
(
SELECT DENSE_RANK() OVER (PARTITION BY ID ORDER BY NUM DESC)as ROW_ID,* FROM #tempB ) as B
ON A.ROW_ID = B.ROW_ID









-------------------------
R...



Have you noticed that the question was asked in SQL Server 2000 forum?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-11-09 : 04:41:18
Hi

Yes so that i have mentioned like this...Try this...its working(2005/2008)...but not suggested.

-------------------------
R...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-09 : 04:45:01
quote:
Originally posted by rajdaksha

Hi

Yes so that i have mentioned like this...Try this...its working(2005/2008)...but not suggested.

-------------------------
R...



If OP doesn't have them, how is it possible to run them?
Let OP give more informations

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-11-09 : 09:02:53
Hi velliraj

I don’t know your scenario. May be its helpful for you.


CREATE TABLE #temp1
(

Empid INT NULL,
salary INT NULL,
ID2 INT
)
GO

CREATE TABLE #temp2
(
Empid INT NULL,
phone INT NULL,
ID2 INT
)
GO

INSERT INTO #temp1(Empid,salary)
SELECT 1, 5000 UNION ALL
SELECT 1, 2000 UNION ALL
SELECT 1, 3000

INSERT INTO #temp2(Empid,phone)
SELECT 1, 12345 UNION ALL
SELECT 1 ,3456

SELECT * FROM #temp1
SELECT * FROM #temp2


DECLARE @LOOPINDEX INT

SET @LOOPINDEX = 0
UPDATE T
SET ID2 = @LOOPINDEX,@LOOPINDEX=@LOOPINDEX + 1
FROM #temp1 T

SET @LOOPINDEX = 0
UPDATE T
SET ID2 = @LOOPINDEX,@LOOPINDEX=@LOOPINDEX + 1
FROM #temp2 T

SELECT * FROM #temp1
SELECT * FROM #temp2

SELECT A.Empid, A.salary , B.phone FROM
(

SELECT * FROM #temp1 ) as A
LEFT OUTER JOIN
(
SELECT * FROM #temp2 ) as B
ON A.ID2 = B.ID2


DROP TABLE #temp1
DROP TABLE #temp2


-------------------------
R...
Go to Top of Page
   

- Advertisement -