Query help

  • Hi All,

    create table #abcd

    (id int,

    code varchar(10),

    relt_id int

    )

    insert into #abcd

    (id, code, relt_id)

    select 1, 'abc', 2

    union all

    select 2, 'bcd', 1

    union all

    select 2, 'asg', null

    union all

    select 3, 'cde', null

    union all

    select 2, 'abd', 1

    union all

    select 4, 'bcd', null

    union all

    select 4, 'bfh', 2

    I have a requirement, where I have a table(Code included).

    My requirement is the relt_id should be same as id and the code = 'abd'

    I have tried doing that using self join, but it returned two, rather that one.

    Any ideas how to achieve this?

    Thanks in advance.

  • any good?

    SELECT a.id,

    a.code,

    a.relt_id

    FROM dbo.#abcd a

    INNER JOIN dbo.#abcd b

    ON a.relt_id = b.id

    WHERE ( a.code = 'abd' )

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • Thanks a lot Gah,

    Worked like a GEM.

    Appreciate your help.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply