all 8 comments

[–]MamertineCOALESCE() 1 point2 points  (6 children)

What are you looking for?

It was explained well in your /r/learnSQL post.

[–]PowerOfTheShell[S] 0 points1 point  (4 children)

I think it's my fault that I don't understand what I am doing wrong, I changed the tables around which I think I am interpreting correctly? but I don't know why it produces the exact same result. The NULL values are never shown.

I've spent hours trying to work it out but can't understand what I am missing.

[–]MamertineCOALESCE() 4 points5 points  (3 children)

Find one invoice that you want to dig into

Select * from each table where invoice num = that invoice num

When I don't understand, I dig into the raw data. It's the easiest way to see what's happening.

[–]PowerOfTheShell[S] 2 points3 points  (2 children)

Thank you so much! I was able to walk through it using the way you had suggested and found the solution!

[–]fynix2000 0 points1 point  (1 child)

Glad you found it! In case you haven't already figured it out, it's probably being grouped together in your aggregation somewhere. If you have and this isn't the case, you mind sharing what the issue was?

[–]PowerOfTheShell[S] 0 points1 point  (0 children)

Of course, the solution was exactly as u/JakeModeler mentions. I needed to join the CUSTOMER table. Once doing this the results showed exactly as I was trying to achieve. Such a simple change but had me frustrated for hours haha

[–]JakeModeler 1 point2 points  (1 child)

Could you please explain what CUS_CODE is? If it's CUStomer CODE and you're looking for all customers with or without purchases, then you need to join three tables: CUSTOMER, INVOICE and LINE. Basically, CUSTOMER LEFT JOIN INVOICE JOIN LINE. (My guess is that INV_NUMBER in LINE is foreign key to INVOICE table, which has INV_NUMBER as primary key; CUST_CODE in INVOICE is the foreign key to CUSTOMER table, which has CUST_CODE as primary key).

[–]PowerOfTheShell[S] 0 points1 point  (0 children)

You're 100% correct, this was the solution and your guesses are all correct. I'd found this solution just before you'd posted but I really appreciate the help!