I have two tables, one for invoices and one for incoming payments. An incoming payment can be joined to an invoice by a foreign key like so:
from invoices t1 inner join incoming_payments t2 on t1.receiptnum = t2.docnum
The question: I want to return all invoices which have more than one payment posted against them. For each invoice I want to return its docnum, which is just a unique id for the invoice.
Here are some things I tried which did not work:
select t0.docnum
from invoices t0 inner join incoming_payments t1 on t0.receiptnum = t1.docentry
group by t0.docnum
having count(t0.docnum) > 1
and
select t0.docnum
from invoices t0 inner join incoming_payments t1 on t0.receiptnum = t1.docentry
group by t0.receiptnum, t0.docnum
having count(t0.receiptnum) > 1
Any ideas?