tags:

views:

100

answers:

1

I have two tables as follow:

t_product p_id, p_name...

t_order o_id, o_product, o_quantity

that is my query:

   SELECT t_product.*, t_order.* 
    FROM t_product 
    JOIN t_order ON p_id = o_product 
ORDER BY o_product

it return:

p_id | p_name     | o_quantity
---------------------------------
01   | prod_01    | 30
01   | prod_01    | 20
02   | prod_21    | 0
03   | prod_23    | 90
03   | prod_23    | 20

it's ok, but I need the sum of each product instead line by line product quantity. I try put sum into the query on the MySql admin page for test purpose and it work perfectly, but when I try the same into the ASP page running on Windowns Server 2008 with the same MySql, it return 0 row.

Why it work on MySql admin page and don't within ASP page?

+1  A: 

Try this query it will show you the total order quantity for each product.

 SELECT p_id, p_name,sum(o_quantity)
    FROM t_product 
    JOIN t_order ON p_id = o_product 
GROUP BY p_id,P_name
ORDER BY o_product
awright18