Roman Neuhauser wrote:

# [EMAIL PROTECTED] / 2003-06-04 09:17:01 -0400:


I need all data in sales1 and sales2, but only for records from acc that are in either/both sales1, sales2.


SELECT acc.name, acc.phone, acc.acctno,
sales1.amt AS mo1sales, sales2.amt AS mo2sales,
(sales1.amt - sales2.amt) AS diff
FROM acc
LEFT JOIN sales1 USING acctno
LEFT JOIN sales2 USING acctno
ORDER BY diff


To make sure that the rows exist in either sales1 or sales2, include a
WHERE (sales1.acctno IS NOT NULL OR sales2.acctno IS NOT NULL).

Also, I suspect that sales1 and sales2 should really be a single 'sales'
table with an extra column indicating which month the sales are for (and
maybe one for year as well), but I don't have enough information to be sure.

Bruce Feist





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



Reply via email to