sql server - 连接空值

发布于 2024-11-10 12:56:16 字数 294 浏览 4 评论 0原文

我有两张桌子。一个有链接列表,另一个包含其样式(如果有)。 后者是一个稀疏表,即当它们的值为空时,它没有相应的行。 我运行以下查询:

select hl.*, hls.colorCode, hls.bold
from HeaderLinks hl, HeaderLinkStyles hls 
where hl.LinkId = hls.linkID
order by row asc, [column] asc

我想修改它,以便如果特定记录不存在行,这些列将在结果集中接收空值。

谢谢你!

I have two tables. One has a list of links and the other one holds thier styles if available.
The later is a sparse table, i.e. it does not have corresponding rows when their values are null.
I run the following query:

select hl.*, hls.colorCode, hls.bold
from HeaderLinks hl, HeaderLinkStyles hls 
where hl.LinkId = hls.linkID
order by row asc, [column] asc

I want to modify this so that if a row does not exist for the specific record, these columns will receive null values in the result set.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

圈圈圆圆圈圈 2024-11-17 12:56:17

左连接

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
时光磨忆 2024-11-17 12:56:17

要获取不存在记录的 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

在此处输入图像描述

在此处检查连接:Visual SQL连接的表示

To get the NULL for not exist records you need to use either LEFT OUTER JOIN or RIGHT OUTER JOIN on the table.......

Select hl.*, hls.colorCode, hls.bold From HeaderLinks hl
Left Join HeaderLinkStyles hls on hl.LinkId = hls.linkID order by row asc,[column] ASC

enter image description here

Check joins over here : Visual Representation of SQL Joins

零度℉ 2024-11-17 12:56:17

当未找到匹配项时,leftfull 连接将用 null 填充行:

select  *
from    HeaderLinks hl
full outer join
        HeaderLinkStyles hls 
on      hl.LinkId = hls.linkID 

左连接仅用 null 填充右侧表,右连接仅填充左手表,而全连接则填充两者。有关直观说明,请参阅A Visual Explanation of SQL 连接

A left or full join will fill a row with null when no match is found:

select  *
from    HeaderLinks hl
full outer join
        HeaderLinkStyles hls 
on      hl.LinkId = hls.linkID 

A left join only fills the right hand table with nulls, a right join only the left hand table, and a full join fills both. For a visual illustration see A Visual Explanation of SQL Joins.

指尖凝香 2024-11-17 12:56:17

您需要使用左外联接

select hl.*, hls.colorCode, hls.bold
from HeaderLinks hl
    left join HeaderLinkStyles hls on
      hl.LinkId = hls.linkID  
order by row asc, [column] asc

使用外联接

You need to use left 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

Using Outer Joins

白馒头 2024-11-17 12:56:17

您需要使用 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

You need to use 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文