Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Posts
    3

    Question Unanswered: updating grouped rows...

    I am new here, and I am sure this is a simple query, but im being forcefed database chores from my job, so i have to teach this stuff to myself/get help from places like this,
    I need help with a query,
    lets say that there are columns a,b,c,d,e,f,g
    if columns c,d,e are the same, than I want the info in column g changed to the info in column b in the first record of that group
    the reason I am doing this is,
    I have like items (sku's) grouped in my database, and i want to create a blanket part number for skus that have matching descriptions which is the information in colums c,d,e,
    I want to link them to the part number of the first product with that description, and add that part number in a new column at the end of the grouped SKU's record

    this is what i start out with

    a b c d e f g
    2 4 5 6 9 8
    2 5 5 6 9 9
    2 7 5 6 0 5
    1 2 3 4 5 6
    1 3 3 4 5 7
    1 4 3 4 5 8
    1 5 3 4 5 9

    i want to end up with
    a b c d e f g
    2 4 5 6 9 8 4
    2 5 5 6 9 9 4
    2 7 5 6 0 5 7
    1 2 3 4 5 6 2
    1 3 3 4 5 7 2
    1 4 3 4 5 8 2
    1 5 3 4 5 9 2

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    update YourTable
    set g = GroupQuery.Minb
    from YourTable
    inner join (select c, d, e, min(b) Minb from YourTable group by c, d, e) GroupQuery
    on YourTable.c = GroupQuery.c
    and YourTable.d = GroupQuery.d
    and YourTable.e = GroupQuery.e
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Jul 2004
    Posts
    3

    Thanks

    Thank you very much, you are a lifesaver.
    Tim

Posting Permissions

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