Query Help ???

  • MainItemTable (Table1)
    MainItemsQuantity
    Item 1100
    Item 2200
    Item 3300
    Item 4400
    Item 5500
    SubstituteItemTable (Table2)
    MainItemsSubstituteItemsQuantity
    Item 1Substitute Item 1110
    Item 1Substitute Item 2120
    Item 2Substitute Item 3210
    Item 2Substitute Item 4220
    Item 3Substitute Item 5310
    This is the way I want to display data. Please help

     

     

    MainItemsSubstituteItemsQuantity
    Item 1100
    Item 1Substitute Item 1110
    Item 1Substitute Item 2120
    Item 2200
    Item 2Substitute Item 3210
    Item 2Substitute Item 4220
    Item 3300
    Item 3Substitute Item 5310
    Item 4400
    Item 5500
  • Try using a cross join in your query

  • This is a simple UNION:

    Select MainItems, '' As SubstituteItems, Quantity

    From MainItemTable

    Union

    Select SubstituteItemTable, SubstituteItems, Quantity

    From SubstituteItemTable

    Order by 1, 2

     

  • CAN i CREATE A VIEW USING ORDER BY CLAUSE

  • Try this

    SELECT MI.MainItems, '' AS Substitute, MI.Quantity

    FROM MainItemsTable MI

    UNION

    SELECT MI.MainItems, SI.SubstituteItems AS Substitute, SI.Quantity

    FROM MainItemsTable AS MI

    INNER JOIN SubstituteItemsTable AS SI ON MI.MainItems = SI.MainItems

    ORDER BY MainItems, Substitute

     

    Patrick Duflot

  • Why do you need a join ?

  • To answer an above question, no you cannot use an ordery by clause IN  a view...but ON  a view you can.

     

    Additionally, I think this is pretty straight forward.

    Unions listed should work fine.

     

     

Viewing 7 posts - 1 through 6 (of 6 total)

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