Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2010
    Posts
    2

    Unanswered: How to group the column in SQL

    Hi,

    I am having a table which contains emp_name, basic_pay, PF, other_info.

    Now i want to display as,

    emp_name1 basic_pay
    emp_name1 PF
    emp_name1 Other_info

    Like this, Instead of displaying in single row, i want to display in different row based on that emp_name.

    How Can I achieve this.

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    it is best to return a single row to your report\ client application and format there. If you must do this in SQL then you will have to write a series of SELECT statements using UNION ALL. You will also probably have to CAST() your data to VARCHAR too.

  3. #3
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Something like:
    Code:
    SELECT * 
    FROM ( 
      SELECT emp_name1, basic_pay FROM the_table_with_no_name
      UNION ALL 
      SELECT emp_name1, pf FROM the_table_with_no_name
      UNION ALL
      SELECT emp_name1, other_info FROM the_table_with_no_name
    ) 
    ORDER BY emp_name1

    You will also probably have to CAST() your data to VARCHAR too.
    Very good point!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •