I have a SQL table that includes invoices and another table that includes the lines of the invoices. i’m trying to grab in the lines ones a Price amount on the line to add to my query. my data looks like this (simplified as there is tens of fields in each table and thousands of lines)
Invoice table
InvNumber | ShipCost
1 | 500
2 | 1000
Invoice_line table
InvNumber | Product | GL | Price
1 | ABC | 2 | 10
1 | Z | 1 | 50
2 | X | 2 | 15
I need to get a query that will grab the price on the invoice line table based on the GL account and add it to my query so in my example if the GL is 1 I need to have that price added to my query
I created a query with a LEFT JOIN but when I use it it created a Line that the price is NULL and another line so i’m missing a little something
Here's my query
SELECT DISTINCT
InvNumber,
ShipCost,
CASE
WHEN Invoice_line.GL = '1' THEN Invoice_line.Price
ELSE NULL
END AS Price
FROM Invoice
LEFT JOIN Invoice_line ON Invoice.InvNumber = Invoice_line.InvNumber
Result that it gives me now
InvNumber | ShipCost | Price
1 | 500 | 50
1 | 500 | NULL
2 | 1000 | NULL
Expected Result
InvNumber | ShipCost | Price
1 | 500 | 50
2 | 1000 | NULL
I tried a SELECT DISTINCT but that didn’t change anything.
Also played with different type of JOIN but nothing gave me what I was expecting
Not sure what i’m missing to have the result that i’m looking for