Joining a table to itself with the unique ID the same, Possible????

  • Hello,

    I'm hoping that SQL can do the below...

    Table Product_Options has been filtered by the ProductID, which results in the 2 OptionID's I need

    to filter Table Product_Options_Values...

    For easy explanation 962 is the parent and 963 is the Child in the Table Product_Options...

    Can a query be built by joining the 2 tables or Self Joining the Table Product_Options_Values, to produce the results down below.... ( )

    Thanks,

    John

    OptionIDDateCreatedProductIDOptionType

    962 52:44.4 6818 Size

    963 52:44.4 6818 Color

    ValueID DateCreatedOptionIDVendorSKUShortDesc

    401952:43.1 962NULLNo Selection

    402052:43.1 962NULLAdult- US-001-UA

    402152:43.1 962NULLPediatric- US-001-UP

    402252:43.1 963NULLNo Selection

    402352:43.1 963NULLOrange-OR

    402452:43.1 963NULLHot Pink-HP

    402552:43.1 963NULLLight Pink-LP

    402652:43.1 963NULLBurgundy-BD

    402752:43.1 963NULLRed-RD

    402852:43.1 963NULLYellow-YL

    402952:43.1 963NULLLight Green-LG

    403052:43.1 963NULLGreen-GR

    403152:43.1 963NULLTeal-TL

    403252:43.1 963NULLLight Blue-LB

    403352:43.1 963NULLNavy-NA

    OptionIDShortDescOptionIDShortDesc

    962No Selection963No Selection

    962No Selection963Orange-OR

    962No Selection963Hot Pink-HP

    962No Selection963Light Pink-LP

    962No Selection963Burgundy-BD

    962No Selection963Red-RD

    962No Selection963Yellow-YL

    962No Selection963Light Green-LG

    962No Selection963Green-GR

    962No Selection963Teal-TL

    962No Selection963Light Blue-LB

    962No Selection963Navy-NA

    962Adult- US-001-UA963No Selection

    962Adult- US-001-UA963Orange-OR

    962Adult- US-001-UA963Hot Pink-HP

    962Adult- US-001-UA963Light Pink-LP

    962Adult- US-001-UA963Burgundy-BD

    962Adult- US-001-UA963Red-RD

    962Adult- US-001-UA963Yellow-YL

    962Adult- US-001-UA963Light Green-LG

    962Adult- US-001-UA963Green-GR

    962Adult- US-001-UA963Teal-TL

    962Adult- US-001-UA963Light Blue-LB

    962Adult- US-001-UA963Navy-NA

    962Pediatric- US-001-UP963No Selection

    962Pediatric- US-001-UP963Orange-OR

    962Pediatric- US-001-UP963Hot Pink-HP

    962Pediatric- US-001-UP963Light Pink-LP

    962Pediatric- US-001-UP963Burgundy-BD

    962Pediatric- US-001-UP963Red-RD

    962Pediatric- US-001-UP963Yellow-YL

    962Pediatric- US-001-UP963Light Green-LG

    962Pediatric- US-001-UP963Green-GR

    962Pediatric- US-001-UP963Teal-TL

    962Pediatric- US-001-UP963Light Blue-LB

    962Pediatric- US-001-UP963Navy-NA

  • Please, post proper DDL, sample data and expected results.

    See this article for reference:

    http://www.aspfaq.com/etiquette.asp?id=5006

    Anyway, what you're describing is a self join. In order to achieve that, you need to introduce aliases for the referenced objects.

    E.g.:

    useAdventureWorks

    selectEmployees.Title as EmployeeTitle

    ,Managers.Title as ManagerTitle

    fromHumanResources.Employee Employees

    inner joinHumanResources.Employee Managers

    onManagers.EmployeeID = Employees.ManagerID

    go

    ML

    ---
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

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

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