# [EMAIL PROTECTED] / 2003-06-04 09:17:01 -0400:
> acc.name, acc.phone, acc.acctno, sales1.amt as mo1sales, sales2.amt as
> mo2sales, (sales1.amt - sales2.amt) as diff SORT by diff
>
> I need all data in sales1 and sales2, but only for records from acc that
> are in either/both sales1, sales2.
>
> I tried:
> select .... from acc,sales1,sales2 where acc.acctno=sales1.acctno and
> acc.acctno=sales2.acctno
> I got only records which were in all three tables.
>
> I looked at using join, but can not determine which style of JOIN I need,
> nor how to write the JOIN statement. Can someone please help?
this?
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
you might need to employ a function or two on the selected values
to coerce the NULLs into something that will make sense in the
computations.
--
If you cc me or remove the list(s) completely I'll most likely ignore
your message. see http://www.eyrie.org./~eagle/faqs/questions.html
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]