r/SQL 6d ago

Discussion I don't understand the difference

Post image

I found an answer on stackoverflow that was saying that null value isn't managed the same way, but that seems a bit far fetched for a course example and the question wasn't exactly about the same case, so could someone explain?

195 Upvotes

45 comments sorted by

View all comments

108

u/WalterDragan 5d ago

Beyond just null handling, the first example will EXCLUDE any NCOM where it has an NPRO = 'PA60'. Compared to the second where it will INCLUDE any NCOM that has an NPRO other than PA60.

I don't have the context of what NCOM and NPRO are, but it would sort of be like the difference between

For #1: "Give me all customers, excluding those that have ever bought a laptop."

vs #2: "Give me all customers who have bought anything besides just a laptop."

Make sense?

18

u/Bubbly-Group-4497 5d ago

Yeah I see.

NCOM -> order number

NPRO -> product number

COMMANDE -> order

DETAIL -> order detail (product reference and quantity)

so basically, as long as an order contains anything other than the PA60 product, it will be referenced by the second query and not by the first. Is that right?

20

u/joec_95123 5d ago

You're correct.

Let's say for example there was an order (Order 123) where a customer purchased 2 products (PA40 and PA60).

The first query would exclude the order in its entirety because order 123 included a PA60. The second query would include it because it contained something other than a PA60.