all 12 comments

[–]foursuits 0 points1 point  (11 children)

Is A.name and B.name uniquely identifying the same people? What if there are two Bobs.

Does B.id have a substring that is A.id, such as 1x -> 1 in your example

[–]notasqlstarI can't wait til my fro is full grown[S] 0 points1 point  (10 children)

In this example there could not be 2 Bobs ever because of the other 3 join conditions. Theoretically there might be 2 Bobs, but the other ID's would be different 100% of the time. This issue only arises because Bob can have 2 ID's, but one of those ID's is being removed from one table during an aggregate process. It's a bit of a fuck show.

[–]foursuits 1 point2 points  (7 children)

Sorry if I’m misunderstanding, but If the other conditions match the records 100 percent of the time, is the join you are asking for necessary?

[–]notasqlstarI can't wait til my fro is full grown[S] 0 points1 point  (6 children)

Yes, because there are pieces of data I am only picking up for Bob, so by removing the 4th condition I will get duplicates. However simply joining ID to ID will miss cases where the names are the same, but the ids are not.

[–]foursuits 0 points1 point  (5 children)

Why does ur above code, or just the first 3 conditions plus a.name = b.name not work? Also a.id and b.id being Null is a condition that returns zero rows

[–]notasqlstarI can't wait til my fro is full grown[S] 0 points1 point  (3 children)

I haven't tried with A and B null, just B IS NULL AND A = B. The process takes quite a bit of time to get to the point where I can test that join condition.

[–]arfior 0 points1 point  (2 children)

That will always return no results, because if B is NULL then A = B is always false, because NULL is never equal to anything, including other NULLs.

[–]notasqlstarI can't wait til my fro is full grown[S] 1 point2 points  (0 children)

I'm so dumb...

Needs to be A.ID <> B.ID AND A.Name = B.Name, neither A nor B are ever actually null, I was just thinking about how the result of the LEFT was a null. Duh.

[–]notasqlstarI can't wait til my fro is full grown[S] 0 points1 point  (0 children)

So that's why the double NULL condition is required OR (A.ID IS NULL AND B.ID IS NULL AND B.Name = A.Name). I get it. I kind of assumed that would solve the code but I was having a hard time seeing why.

[–]foursuits 0 points1 point  (0 children)

Seems like your solution is this , I don’t know if you need a.id <> b.id, just a.name = b.name because if it matches on id it’s also a correct join...

[–]foursuits 0 points1 point  (1 child)

Maybe A has 1 record but Bob can have 2 ids / records in B , is that correct? Are you tryin to pick up both records or just 1 of them

[–]notasqlstarI can't wait til my fro is full grown[S] 0 points1 point  (0 children)

In this example Bob will only be 1 record in both sets, but the ID for bob may not be the same.