sql server-加入空值

| 我有两张桌子。一个包含链接列表,另一个包含可用的样式。 后者是一个稀疏表,即当它们的值为空时,它没有对应的行。 我运行以下查询:
select hl.*, hls.colorCode, hls.bold
from HeaderLinks hl, HeaderLinkStyles hls 
where hl.LinkId = hls.linkID
order by row asc, [column] asc
我想对此进行修改,以便如果特定记录不存在任何行,则这些列将在结果集中接收空值。 谢谢!     
已邀请:
        左加入
Select hl.*, hls.colorCode, hls.bold 
From HeaderLinks hl
Left Join HeaderLinkStyles hls on hl.LinkId = hls.linkID
order by row asc,[column] ASC
    
        要获取不存在的记录的NULL,您需要在表上使用LEFT OUTER JOIN或RIGHT OUTER JOIN。
Select hl.*, hls.colorCode, hls.bold From HeaderLinks hl
Left Join HeaderLinkStyles hls on hl.LinkId = hls.linkID order by row asc,[column] ASC
在此处检查联接:SQL联接的可视表示     
        如果找不到匹配项,则
left
full
连接将用
null
填充一行:
select  *
from    HeaderLinks hl
full outer join
        HeaderLinkStyles hls 
on      hl.LinkId = hls.linkID 
左联接仅将空表填充为右表,右联接仅将左表填充为全联接。有关直观的说明,请参见SQL连接的直观说明。     
        您需要使用左外部联接
select hl.*, hls.colorCode, hls.bold
from HeaderLinks hl
    left join HeaderLinkStyles hls on
      hl.LinkId = hls.linkID  
order by row asc, [column] asc
使用外部联接     
        您需要使用LEFT JOIN
Select 
  hl.*, 
  hls.colorCode, 
  hls.bold 
from 
  HeaderLinks hl 
LEFT JOIN 
  HeaderLinkStyles hls on hl.LinkId = hls.linkID
order by 
  row asc,[column] ASC
    

要回复问题请先登录注册