union, intersection

  • Hi,

    how does intersection takes place in sql server ( table a and table b - there are some rows that have a.col1=b.col1, but there are rows whose a.col1 is different). Col1 is not a primary key.

    Thnx.

     

     

  • What is it that you want to show?

    If you want to show only data where there are matches, use inner join.

    Select

    a.Col1, a.Col2, b.Col1, b.Col2, b.Col3

    from tableA a

    INNER JOIN tableB b

    on a.Col1 = b.Col2

    If you want to show all matches, plus all rows from tableA, use a LEFT OUTER JOIN:

    Select

    a.Col1, a.Col2, b.Col1, b.Col2, b.Col3

    from tableA a

    LEFT OUTER JOIN tableB b

    on a.Col1 = b.Col2

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply