0

User.Id ごとにすべてのコメントを一覧表示する StackExchange DataExplorer クエリを作成しました。クエリは機能し、とIdの を返します。私が理解していないのは、 の 2 番目の列が空である理由です。questionsanswersanswers

DECLARE @UserId int = ##UserId##

Select p.Id
   , '<a href=https://stackoverflow.com/questions/' 
          + Cast(p.Id as varchar(20)) + '>'           
          + Cast(p.Id as varchar(20)) 
          + ' - ' + p.Title + '</a>'
   , c.Text
      FROM Users u            
      Join Comments c ON c.UserId = @UserId
      JOIN Posts p ON p.Id = c.PostId
      where u.Id = @UserId AND p.Id IS NOT NULL

列がNULLであると仮定しても、列p.TitleはNULLでp.Idはないため、この部分は

'<a href=https://stackoverflow.com/questions/' 
              + Cast(p.Id as varchar(20)) + '>'           
              + Cast(p.Id as varchar(20)) 
              + ' - ' + p.Title + '</a>'

この質問に従って何かを返します。しかし、2 番目の列は完全に空です。

なぜそうなのですか?

4

1 に答える 1