Reputation: 31
I'm having an issue with my assignment where it's giving me more than one "minimum" date.
The problem is to create a table variable that shows the earliest invoice sent by each vendor, including the invoice total. I've got the table variable creation part working, but I'm having some issues with the query I'm using to populate the table.
This is the query I've been using:
SELECT VendorID, MIN(InvoiceDate) AS EarliestInvoiceDate, InvoiceTotal
FROM Invoices
GROUP BY VendorID, InvoiceTotal
ORDER BY VendorID, EarliestInvoiceDate
But it's giving two invoices for some of the vendors, when I should only be getting one. For example, the first vendor it shows in the result set has two invoices showing for it, with two different dates. One in November and one in December, but it should only be showing the November one.
I have also tried using LEAST() instead of MIN(), but LEAST() produced the exact same results as MIN().
Upvotes: 0
Views: 14