Hey, this is probably a pretty basic SQL question -- i'm not a SQL
genious by any means.
I have two tables, both identical for the purposes of this question.
table a
table b
table b has some records which are meant to "replace" some rows from
table a (same IDs) if they exist. basically, b overrides the rows in a
if they exist in b.
table a
- row a.1
- row a.2
- row a.3
table b
- row b.2 --> same id as a.2
therefore recordset looks like: a.1, b.2, a.3
...not sure how else to explain it.
what type of join am i looking for here?
just need a push in the right direction ...
thanksselect * from table1 as a inner join table2 as b on a.[id] = b.[id]
where b.[id] is null
union all
select * from tale2
order by [id] asc;
AMB
"rob" wrote:
> Hey, this is probably a pretty basic SQL question -- i'm not a SQL
> genious by any means.
> I have two tables, both identical for the purposes of this question.
> table a
> table b
> table b has some records which are meant to "replace" some rows from
> table a (same IDs) if they exist. basically, b overrides the rows in a
> if they exist in b.
> table a
> - row a.1
> - row a.2
> - row a.3
> table b
> - row b.2 --> same id as a.2
> therefore recordset looks like: a.1, b.2, a.3
> ...not sure how else to explain it.
> what type of join am i looking for here?
> just need a push in the right direction ...
> thanks
>|||Alejandro Mesa wrote:
> select * from table1 as a inner join table2 as b on a.[id] = b.[id]
> where b.[id] is null
> union all
> select * from tale2
> order by [id] asc;
>
> AMB
Unions! I forgot about Unions. Thanks! I'll be in touch if I continue to
have a problem.
:rob|||It sounds like you want to use a left join:
SELECT ISNULL( B.Col1, A.Col1 ) AS Col1
FROM A
LEFT JOIN B ON A.Id = B.Id
ORDER BY SomeColumn
You can do the ISNULL for every column in the tables and that will allow
you to have any entries in B override the values in the corresponding row
in A.
Hope that helps,
BC
rob <rcherny@.nospamnavarts.com> wrote in news:#sNGWg6MFHA.3788
@.tk2msftngp13.phx.gbl:
> Hey, this is probably a pretty basic SQL question -- i'm not a SQL
> genious by any means.
> I have two tables, both identical for the purposes of this question.
> table a
> table b
> table b has some records which are meant to "replace" some rows from
> table a (same IDs) if they exist. basically, b overrides the rows in a
> if they exist in b.
> table a
> - row a.1
> - row a.2
> - row a.3
> table b
> - row b.2 --> same id as a.2
> therefore recordset looks like: a.1, b.2, a.3
> ...not sure how else to explain it.
> what type of join am i looking for here?
> just need a push in the right direction ...
> thanks
>
没有评论:
发表评论