Query:

  • 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

  • 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

  • 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

  • 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

  • Thanks,I got my answer.

  • 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