Jewel142
ISP
- Jun 17, 2009
- 39
I am new to SQL and I'm having a hard time with getting the right results from my subquery.
I am reporting off of three tables, Vendors, Invoices and Line Items and I am trying to get the results for each invoice that has more than one line item in the InoviceLines Table.
Here is my code so far but for some reason, I'm only getting four records instead of the six that I should be getting. (I tested it in Excel). What am I doing wrong? I've tried changing my joins but nothing seems to work.
SELECT Vendors.VendorName, Invoices.InvoiceID, InvoiceSequence, InvoiceLineItems.InvoiceLineItemAmount
FROM Vendors INNER JOIN
Invoices ON Vendors.VendorID = Invoices.VendorID RIGHT OUTER JOIN
InvoiceLineItems ON Invoices.InvoiceID = InvoiceLineItems.InvoiceID
WHERE InvoiceLineItems.InvoiceSequence IN
(SELECT InvoiceLineItems.InvoiceSequence
FROM InvoiceLineItems
WHERE InvoiceLineItems.InvoiceSequence >1)
I am so frustrated right now. Any help would be greatly appreciated!
Jewel~
I am reporting off of three tables, Vendors, Invoices and Line Items and I am trying to get the results for each invoice that has more than one line item in the InoviceLines Table.
Here is my code so far but for some reason, I'm only getting four records instead of the six that I should be getting. (I tested it in Excel). What am I doing wrong? I've tried changing my joins but nothing seems to work.
SELECT Vendors.VendorName, Invoices.InvoiceID, InvoiceSequence, InvoiceLineItems.InvoiceLineItemAmount
FROM Vendors INNER JOIN
Invoices ON Vendors.VendorID = Invoices.VendorID RIGHT OUTER JOIN
InvoiceLineItems ON Invoices.InvoiceID = InvoiceLineItems.InvoiceID
WHERE InvoiceLineItems.InvoiceSequence IN
(SELECT InvoiceLineItems.InvoiceSequence
FROM InvoiceLineItems
WHERE InvoiceLineItems.InvoiceSequence >1)
I am so frustrated right now. Any help would be greatly appreciated!
Jewel~