Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2012
    Posts
    6

    Unanswered: Group multiple rows into one

    Hi, I need help in creating a query to group identical rows into one and placing corresponding data in appropriate columns for a table named items, what I mean is that I have a table structured as below

    Itemcode, Description, Period1, Period2, Period3
    001--------Desc--------233,---------,------- <<ROW1
    001--------Desc ------------ ,100,------------ <<ROW2
    001--------Desc ------,--------,-------,300 <<ROW3

    Row one contains a value in Period1
    Row two contains a value in Period 2
    Row three contains a value in Period 3

    I need to create a query so that the end result would look like this;

    Itemcode, Description, Period1, Period2, Period3
    001 --------Desc -------233 ----100 ---300

    Can you please help / guide in creating an sql query to get the above result?

    Thanks

    Kevin

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT Itemcode
         , Description
         , MAX(Period1) AS Period1
         , MAX(Period2) AS Period2
         , MAX(Period3) AS Period3
      FROM daTable
    GROUP
        BY Itemcode
         , Description
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2012
    Posts
    6
    thanks, it perfectly worked!!

Posting Permissions

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