Obtain unique pairs from two tables

  • I want to generate a list of all the unique pairs from these two tables. Such as:

    MatCostType : Loc

    1 : A

    1 : B

    1 : C

    2 : A

    2 : B

    2 : C

    ...

    3 : C

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[TableA](

    [MatCostType] [char](1) NOT NULL

    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF

    GO

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[TableB](

    [Loc] [char](3) NULL

    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF

    GO

    insert into TableA(MatCostType)

    Select '1'

    union all

    Select '2'

    union all

    Select '3'

    Go

    insert into TableB(Loc)

    Select 'A'

    union all

    Select 'B'

    union all

    Select 'C'

    Go

    How do I go about this?

    Thanks,

    pat

  • Looks like you want a CROSS JOIN.

    I'd provide the code, but I think you'll get more by reading the link above and coding it yourself.

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

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