I'm a bit new to this, so bear with me if it seems obvious.  :)

I have two tables the content of which I'd like to display in a single
result, ordered by content of fields that have similar content but
different names in the two tables.

This is as far as I've gotten:

SELECT  invoice.invdate AS date,
        invoice.invnum AS comment,
        invoice.amount,
        receivable.date,
        receivable.itemnumber AS comment,
        -receivable.amount
        FROM invoice
        LEFT JOIN receivable USING (custid)
        WHERE invoice.custid='someconstant' AND receivable.custid=invoice.custid
        ORDER BY date;

This (perhaps obviously) doesn't work, giving me a six-column output
with content of 'receivable' *beside* 'invoice' instead of being
intermixed with it.  The result I WANT would have three columns, giving
me a "statement" with both credits and debits to an account.  All in
all, it looks pretty much identical to:

SELECT  invoice.invdate AS date,
        invoice.invnum AS comment,
        invoice.amount,
        receivable.date,
        receivable.itemnumber AS comment,
        receivable.amount FROM invoice,receivable
        WHERE invoice.custid='someconstant' AND receivable.custid=invoice.custid
        ORDER BY date;

I'm obviously on the wrong track.  Is UNION what I want to be using here?

Thanks.

-- 
  Paul Chvostek                                             <[EMAIL PROTECTED]>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to