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

    Join Date
    Nov 2000
    Rep Power
    I'd like to keep one table with all the raw data, and one smaller, summarized table. Whenever the raw table is appended to or modified, I want to run code that will summarize the raw table based on a unique key and keep the summarized data in the smaller table.

    So is there an sql command to combine the select statemenet, with a GROUP BY command and to copy the results to a summarized table?
  2. #2
  3. Wiking
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Sep 2000
    Rep Power
    You could use two queries to accomplish that.

    Run this first to empty the target table:

    DELETE FROM small_table

    Then run this to insert summarized data from big_table into small_table:

    INSERT INTO small_table (field1, field2, field3, field4) SELECT sum(field1), sum(field2), sum(field3), sum(field4) FROM big_table WHERE some_condition GROUP BY field1, field2 ORDER BY field 3


    [This message has been edited by NoXcuz (edited November 28, 2000).]

IMN logo majestic logo threadwatch logo seochat tools logo