join statement

  • i have 2 table let say table A and table B.

    A have values 1,2,3

    B has values 1,2,4

    i want query using joins which give all values like:

    1

    2

    3

    4

    normally joins fetch matching or non matching data .. but how to get over this.

    And this has to be achieved only by joins.

  • Full Outer Joins - http://msdn.microsoft.com/en-us/library/ms187518.aspx

    declare @t1 table (SomeId int)

    declare @t2 table (SomeId int)

    insert into @t1 values (1), (2), (3)

    insert into @t2 values (1), (2), (4)

    selectisnull(t1.SomeId, t2.SomeId) as SomeId

    from@t1 t1

    full outer join @t2 t2 on t1.SomeId = t2.SomeId

    _____________________________________________________________________
    - Nate

    @nate_hughes
  • thanki SSC

  • Hi,

    declare @t1 table (SomeId int)

    declare @t2 table (SomeId int)

    insert into @t1

    Select (1) Union all

    Select (2) Union all

    Select (3)

    insert into @t2

    Select (1) Union all

    Select (2) Union all

    Select (4)

    Select SomeId from @t1

    Union

    Select SomeId from @t2

Viewing 4 posts - 1 through 3 (of 3 total)

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