SQL Server how to use a single SELECT query in this case? -
i performing select on 2 tables, selection conditional on tables' primary id, expect @ 1 result each query. i'd combine queries single select statement. thought should using right (or maybe left) outer join, isn't working me. suggestions?
table table b --------- ---------- id (pk) | aattr id (pk) | battr select aattr, battr right outer join b on b.id = 1 a.id = 1
*edited include sample cases
for example, if tables contained first set of data , querying id of 1
, i'd expect:
[null, 'b']
for second set of data , querying id of 1
, i'd expect:
['a', null]
and third set of data , querying id of 1
, i'd expect:
['a', 'b'] table table b -------- -------- 2 | 1 | b 3 | c 4 | d table table b -------- -------- 1 | 2 | b 3 | c 4 | d table table b -------- -------- 1 | 1 | b 3 | c 4 | d
when join tables, need relate them each other via common column. in case, id.
select a.aattr, b.battr left join b on a.id = b.id a.id = 1;
Comments
Post a Comment