Mike Morton wrote:

I have 2 tables, identical in fields.  One is an 'archived items' table, the
other is a live items.

I want to run a query that will grab the sum of all products in both tables,
like:

The results would display the total qty by item:

QTY NAME

The logic is something like:

sum(table1.qty) + sum(table2.qty)

The query that I came up with is:

select (sum(table1.qty) + sum(table2.qty)) as val,name from table1,table2
group by name order by val desc


It is just a bit off... (like 30000 off the actual count :) )

I have tried to do it with a where and group by clause, but no luck there
either...

Any suggestions?



- you've got a Cartesian results set because you haven't joined the tables. Try joining on name, or writing two queries and then using a UNION.

- ian

--
+-------------------------------------------------------------------+
| Ian Sales                                  Database Administrator |
|                                                                   |
| eBuyer                                      http://www.ebuyer.com |
+-------------------------------------------------------------------+


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to