New answers tagged

0 votes

How to Avoid Duplicates with multiple joins and multiple case statements

SELECT MAX(CASE WHEN T2.id = 2 AND T1.VAL = T2.VAL THEN T1.SAMP END) AS SAMPLE_2, MAX(CASE WHEN T2.id = 3 AND T1.VAL = T2.VAL THEN T1.SAMP END) AS SAMPLE_3 FROM #TABLE1 T1 LEFT JOIN #TABLE2 ...
nbk's user avatar
  • 8,264
2 votes

Why does SQL Server require a LEFT JOIN to retrieve a status that doesn't exist?

Why does SQL Server require a LEFT JOIN on the Status table for child items that do not exist and for the query to display these items? It doesn't, in general. It is just one of the ways to express ...
Paul White's user avatar
  • 84.4k
6 votes
Accepted

Why does SQL Server require a LEFT JOIN to retrieve a status that doesn't exist?

You need to nest your joins. Otherwise what is happening is that it's expecting each individual join clause to return a result, but it can't if the previous one didn't return anything. Essentially, ...
Charlieface's user avatar
2 votes

Why does SQL Server require a LEFT JOIN to retrieve a status that doesn't exist?

Because the join with status table for the child items is happening on basis of ins.InstanceStatusID, dbs.DatabaseStatusID which turns out to be NULL when the joins prior to it takes place in some ...
Shivam Kumar's user avatar

Top 50 recent answers are included