#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Need Grouping Help - Probably easy


    Hey Folks,

    I have a a dataset which I need to collapse and don't know how.

    I have 2 records which I want to sum and make 1. The 2 records have matching identifying number however they have different names. I don't care which name lives through to the result but I need one to. I tried MAX but that didn't work. See Below for example

    Record 1: Name: Red, Dollars: 5, Identity: 612
    Record 2: Name: Red Tree, Dollars: 10, Identity 612

    So for my result I would like it to be a total dollars of 15, Identity 612, and for Name I just need it to pick 1, I don't care if it's Red or Red Tree.

    Your help is greatly appreciated. Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    158
    Rep Power
    10
    SELECT SUM(Dollars) AS totaldollars, MIN(Name) AS randomname, Identity
    FROM table
    GROUP BY Identity;

    I doubt very much that you can get away with just selecting anty random name but I guess you've thought about that :-)

IMN logo majestic logo threadwatch logo seochat tools logo