SQL Server Performance

2 Rows output into 1 row

Discussion in 'General Developer Questions' started by alvin1, Jun 21, 2006.

  1. alvin1 New Member

    How to get the result in 1 row?

    Employee table has the following data:

    Id Name Phone
    --------------
    1 Tom 2545667
    2 Jack 3234342

    How would I retreive these two records into one row like these:

    Id1 Name1 Phone1 Id2 Name2 Phone2
    ----------------------------------
    1 Tom 2545667 2 Jack 3234342

    Thank you.
  2. khtan New Member

  3. FrankKalis Moderator

  4. Madhivanan Moderator

    quote:Originally posted by FrankKalis

    Just for completeness. On SQL Server 2005 you should be able to achieve this by using the new APPLY() construct.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    http://www.insidesql.de
    Heute schon gebloggt?http://www.insidesql.de/blogs
    Is that just like single command similar to PIVOT?

    Madhivanan

    Failing to plan is Planning to fail
  5. FrankKalis Moderator

  6. Madhivanan Moderator

    Thats cool. I hope that will handle more than 8000 characters as well

    Madhivanan

    Failing to plan is Planning to fail
  7. gijomk New Member

    SELECT * FROM
    (SELECT id AS id1, name AS name1, phone AS phone1 FROM Employee WHERE Id = 1) a CROSS JOIN
    (SELECT id AS id2, name AS name2, phone AS phone2 FROM Employee WHERE Id = 2) b
  8. Madhivanan Moderator

    quote:Originally posted by alvin1

    How to get the result in 1 row?

    Employee table has the following data:

    Id Name Phone
    --------------
    1 Tom 2545667
    2 Jack 3234342

    How would I retreive these two records into one row like these:

    Id1 Name1 Phone1 Id2 Name2 Phone2
    ----------------------------------
    1 Tom 2545667 2 Jack 3234342

    Thank you.
    What do you want to get if there are thosands of rows?

    Madhivanan

    Failing to plan is Planning to fail

Share This Page