Jump to content

two DISTINCT() values needed in same query


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.