June 9, 2009 at 1:46 am
Hi All,
I have two tables one is ID another is EVENT.
ID:
IdName
1A
2B
EVENT:
Id Event_Id User
110X
120Y
130Z
210M
220N
230P
I need o/p as following:
ID.Id ID.Name EVENT.User
1Ax
2BM
June 9, 2009 at 2:18 am
I don't undesrtand what you need.
Try reading this http://www.sqlservercentral.com/articles/Best+Practices/61537/ and come back with more info: I'll be glad to help you.
Regards
Gianluca
-- Gianluca Sartori
June 9, 2009 at 2:20 am
Hi,
try this
create table #ID
(
ID1 int,
Name1 varchar(2)
)
insert into #ID
select 1,'A'
union
select 2,'B'
union
select 3,'C'
create table #EVENT
(
id int,
Event_Id int,
user1 varchar(2)
)
insert into #EVENT
select 1,10,'X'
union
select 1,20,'Y'
union
select 1,30,'Z'
union
select 2,10,'M'
union
select 2,20,'N'
union
select 2,30,'O'
union
select 3,10,'P'
union
select 3,20,'Q'
union
select 3,30,'R'
--select * from #id
--select * from #EVENT
1)
select #id.ID1,#id.Name1,
(select top 1 user1 from #EVENT where #EVENT.id = #id.id1 order by #EVENT.Event_Id asc)user1
from #id
2)
select A.ID1,A.Name1,B.user1
from #id A,
(select id,min(user1)user1 from #EVENT group by id
) as B
where
A.id1 = B.id
ARUN SAS
June 9, 2009 at 2:31 am
Is this what you need?
SELECT A.id1, A.Name1, MIN(B.user1) AS User1
FROM #id AS A
INNER JOIN #EVENT AS B
ON A.id1 = b.id
GROUP BY A.id1, A.Name1
-- Gianluca Sartori
June 9, 2009 at 7:37 am
Thanks,I got my answer.
June 9, 2009 at 8:06 am
Glad I could help.
-- Gianluca Sartori
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply