Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have the following sql querry: SELECT invoices.invoicenumber AS [Invoice Numbe

ID: 3772531 • Letter: I

Question

I have the following sql querry:

SELECT invoices.invoicenumber AS [Invoice Number], InvoiceLineItems.InvoiceLineItemDescription AS Description, vendors.VendorName AS Vendor,

   InvoiceLineItems.InvoiceLineItemAmount AS amount, invoices.InvoiceDate AS [Invoice Date]

FROM invoices, InvoiceLineItems, vendors

WHERE invoices.invoicenumber = 'QP58872' OR invoices.invoicenumber = 'Q545443' OR invoices.invoicenumber = 'MABO1489' ;
  

Can someone rewrite this so that the result is the following?

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

It needs to have a regular join and not a join that i have that is dangerous. Thank you

Invoice Number Description Vendor Amount Invoice Date QP58872 MVS Online Library IBM 116.54 2012-01-07 00:00:00 Q545443 MSDN IBM 1083.58 2012-02-09 00:00:00 MABO1489 Quarterly Maintenance Wang Laboratories, Inc. 936.93 2012-02-21 00:00:00

Explanation / Answer

The query will not provide any meaningful result as it will display multiple rows for same invoice number because you are not using references in second and third table. Its better if you can just provide some additional info about the tables like table structure of all three tables and I can then give you the right query.

Regarding your second part of the question here is the join version of your query.

SELECT invoices.invoicenumber AS [Invoice Number], InvoiceLineItems.InvoiceLineItemDescription AS Description, vendors.VendorName AS Vendor,

   InvoiceLineItems.InvoiceLineItemAmount AS amount, invoices.InvoiceDate AS [Invoice Date]

FROM invoices inner join InvoiceLineItems inner join vendors

WHERE invoices.invoicenumber in( 'QP58872' , 'Q545443' , 'MABO1489') ;