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!
谢谢你!
5 个解决方案
#1
4
左连接
Select hl.*, hls.colorCode, hls.bold
From HeaderLinks hl
Left Join HeaderLinkStyles hls on hl.LinkId = hls.linkID
order by row asc,[column] ASC
#2
1
To get the NULL for not exist records you need to use either LEFT OUTER JOIN or RIGHT OUTER JOIN on the table.......
要获得无存在记录的NULL,您需要在表中使用左外连接或右外连接……
Select hl.*, hls.colorCode, hls.bold From HeaderLinks hl
Left Join HeaderLinkStyles hls on hl.LinkId = hls.linkID order by row asc,[column] ASC
Check joins over here : Visual Representation of SQL Joins
检查这里的连接:SQL连接的可视化表示
#3
1
A left
or full
join will fill a row with null
when no match is found:
当没有找到匹配项时,左连接或全连接将用null填充一行:
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.
左连接仅用nulls填充右表,仅用左手表填充右连接,全连接填充这两个表。有关可视化的说明,请参阅SQL连接的可视化解释。
#4
0
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
使用外部连接
#5
0
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
#1
4
左连接
Select hl.*, hls.colorCode, hls.bold
From HeaderLinks hl
Left Join HeaderLinkStyles hls on hl.LinkId = hls.linkID
order by row asc,[column] ASC
#2
1
To get the NULL for not exist records you need to use either LEFT OUTER JOIN or RIGHT OUTER JOIN on the table.......
要获得无存在记录的NULL,您需要在表中使用左外连接或右外连接……
Select hl.*, hls.colorCode, hls.bold From HeaderLinks hl
Left Join HeaderLinkStyles hls on hl.LinkId = hls.linkID order by row asc,[column] ASC
Check joins over here : Visual Representation of SQL Joins
检查这里的连接:SQL连接的可视化表示
#3
1
A left
or full
join will fill a row with null
when no match is found:
当没有找到匹配项时,左连接或全连接将用null填充一行:
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.
左连接仅用nulls填充右表,仅用左手表填充右连接,全连接填充这两个表。有关可视化的说明,请参阅SQL连接的可视化解释。
#4
0
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
使用外部连接
#5
0
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