Jump to content

two DISTINCT() values needed in same query


richrock

Recommended Posts

Hi,

 

Been scratching my head over this for a while now.

 

I have two tables, one purchases, the other won items.  Both have invoice numbers attached to the items in each table, which may (or may not) be unique to each table... eg

 

purchasesinvoicenumwon itemsinvoicenum

Item 1INV-001Won Item 1INV-001

Item 2INV-002Won Item 2INV-003

 

And so on.

 

In order to find all distinct Invoices in both tables, I need to join the tables, and find all DISTINCT() invoice numbers.

 

I've never seen any LEFT JOIN query using more than one DISTINCT statement, so can it be done?  Or am I going completely the wrong way?

 

My thinking is (poor code follows):

 

SELECT DISTINCT(inv_num) as invoices FROM purchases LEFT JOIN won_items ON inv_num GROUP BY purchases.invoices ORDER BY invoices DESC

 

But this is wrong, so....  ???

 

TIA

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.