Question : Need assistance with MYSQL PHP output query

Hi,
   I have an online ordering system which basically uses two tables, these are called:

site_users - this table contains registration details when the customer registers on my website, this also produces a user_id field which is unique to the customer.

ordering - this contains all the online ordering information, including a field called total which stores each individual online order amount.

What i need to do is generate a report which will display all the customer unique, so if they have ordered multiple times they only appear once, but their total is the total of ALL orders...

The code I have so far is:

$result = mysql_query("
      SELECT
            `ordering`.`user_id`,`ordering`.`first_name`, `ordering`.`last_name`, `ordering`.`total`,
            (SELECT
                  sum(`ordering`.`total`)
            FROM
                  `ordering`

            ) AS `total`
      FROM
            `ordering`
      ORDER BY `total` DESC
     
;");

However this outputs all the rows, and the total of ALL orders is the same in each total field.

Can anybody help me for 500 points?

Thanks

Answer : Need assistance with MYSQL PHP output query

Sorry slight correction,


$result = mysql_query("
      SELECT
            `ordering`.`user_id`,`ordering`.`first_name`, `ordering`.`last_name`, `ordering`.`total`,
                  sum(`ordering`.`total`) as `total`
            FROM
                  `ordering`

            GROUP BY   `ordering`.`user_id
            ORDER BY `total` DESC    
;");
Random Solutions  
 
programming4us programming4us