How to join two unrelated tables in sql

后端 未结 4 1176
我在风中等你
我在风中等你 2021-01-03 22:07

I have two tables:

Table 1: Formulas

FormulaId    Formula Text
1            [Qty] * [Rect]
2            [Qty] * [Al]
3            [Mt] * [Cat]  


        
相关标签:
4条回答
  • 2021-01-03 22:24

    You can only do Cross Join. Other joins can be done only with related tables.

    0 讨论(0)
  • 2021-01-03 22:33

    You want to use a CROSS JOIN:

    SELECT FormulaId, Formula, ContextId, [Name]
    FROM Formula
    CROSS JOIN Context
    
    0 讨论(0)
  • 2021-01-03 22:33

    Did you try CROSS APPLY:

    select *
    from context
    cross apply formulas
    order by contextid
    

    See SQL Fiddle With Demo

    0 讨论(0)
  • 2021-01-03 22:34

    You can use the Cartesian Product of the two tables as follows:

    SELECT * FROM Formulas, Context
    

    This would result in M * N rows.

    0 讨论(0)
提交回复
热议问题