SQL Server join table -
i have sql server database 2 tables below. first 1 called "goal_group" , second 1 called "goal".(original tables has fields more this). every goal has goal group. 2 tables linked (have foreign key) ggid.
**table goal group** ggid | ggname | ggdescription 1 operational operational description 2 development development description **table goal** gid | gname | ggid 1 test1 1 2 test2 1 3 test2 1 4 test2 1
i want create view display goal goal groups. view should below.
**final view** gid | gname | ggid | ggname
but though goal table doesn't have row ggid of 2, want have row in view goal group of ggid=2 null values othe fields.
when create view left join below,
select b.gid, b.gname, a.ggid, a.ggname goal_group left join goal b on a.ggid=b.ggid
it doesn't give me row ggid of 2.
am doing wrong. please me this.
you missing outer clause in statement:
select b.gid, b.gname, a.ggid, a.ggname goal_group left outer join goal b on a.ggid=b.ggid
another way accomplish result
select b.gid, b.gname, a.ggid, a.ggname goal_group a, goal b a.ggid*=b.ggid
hth
Comments
Post a Comment