sql server - 连接空值
我有两张桌子。一个有链接列表,另一个包含其样式(如果有)。 后者是一个稀疏表,即当它们的值为空时,它没有相应的行。 我运行以下查询:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
左连接
Left Join
要获取不存在记录的 NULL,您需要在表上使用 LEFT OUTER JOIN 或 RIGHT OUTER JOIN.......
在此处检查连接: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.......
Check joins over here : Visual Representation of SQL Joins
当未找到匹配项时,
left
或full
连接将用null
填充行:左连接仅用 null 填充右侧表,右连接仅填充左手表,而全连接则填充两者。有关直观说明,请参阅A Visual Explanation of SQL 连接。
A
left
orfull
join will fill a row withnull
when no match is found: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.
您需要使用左外联接
使用外联接
You need to use left outer join
Using Outer Joins
您需要使用 LEFT JOIN
You need to use LEFT JOIN