table help.

Discussion in 'Databases' started by Cal813, Sep 30, 2008.

  1. #1
    I have a table with 4 tables in it.

    ID, USERID, THREADID, VOTE

    Now I have a bunch of duplicate THREADID's.. and I want to merge them all so I can add all the VOTE's.

    here is an example:
    ID, USERID, THREADID, VOTE

    1 5 24 1
    2 6 24 1
    3 6 24 3
    4 3 10 1

    I want to merge the 24's, so I can total the votes eg. 5 votes in that thread.

    I assume I have to do a join??
     
    Cal813, Sep 30, 2008 IP
  2. chisara

    chisara Peon

    Messages:
    141
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    SELECT THREADID, SUM(VOTE) FROM VOTETABLE GROUP BY THREADID;
    That should do the trick keep in mind that this query can become rather expensive if the table has a large number of records.
     
    chisara, Sep 30, 2008 IP
    Cal813 likes this.