Skip to content
Advertisement

SQL query that has a lookup field

I have a table Invoices that has 3 fields:

InvoiceProductCode InvoiceQuantity InvoicePrice

InvoiceProductCode can be blank, but if it’s not blank, I would like it to be filled with a value from Products table.

  • products table – ProductCode ProductName

Example 2 lines of data

I would like both rows to be returned even though 2nd row’s InvoiceProductCode is empty (or zero), just that only the first row will have the ProductName; the 2nd row’s ProductName will be empty. i would like to do this in SQL without using Lookup table.

So final result should look like 2 rows:

instead of just 1 row:

how do I structure a query? INNER JOIN on ProductCode will only give me 1 row – the one with the non-empty ProductCode, but the row without the ProductCode is left out.

Any advice?

thanks.

Advertisement

Answer

I think you want left join:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement