Interview Question

  • Hi Experts,

     

    I have faced one question in an interview.

     

    I have two tables called A and B. Table A has 5 records and Table B has 2 records.

    I want all the records from Table A and any one record from Table B.

    for example,

     

    Table A         Table B

    1                  50

    2                  100

    3

    4

    5

    Output should be

    1

    2

    3

    4

    5

    50

    (or)

    1

    2

    3

    4

    5

    100

    Anybody help me to get this output.

     

    Regards

    Karthik

     

     

    karthik

  • create

    table #temp(id int)

    create

    table #temp1(id int)

    insert

    into #temp values (1)

    insert

    into #temp values (2)

    insert

    into #temp values (3)

    insert

    into #temp values (4)

    insert

    into #temp values (5)

    insert

    into #temp1 values (50)

    insert

    into #temp1 values (100)

    select

    id from #temp

    union

    all

    select

    min(id) from #temp1

    select

    id from #temp

    union

    all

    select

    max(id) from #temp1

     

    drop

    table #temp

    drop

    table #temp1

    if your record is fix then this one is simple logic tha you

    can apply

    From Yash Barot

  • Strange question, but I'd go with the union as well.

  • Agree with Steve.

    SELECT * FROM TABALEA UNION SELECT TOP 1 * FROM TABLEB

    Does it work?

  • Thanks Experts !

     

    Regards

    Karthik

    karthik

Viewing 5 posts - 1 through 4 (of 4 total)

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