MySQL cartesian product between two SELECT statements

前端 未结 5 1955
孤街浪徒
孤街浪徒 2020-12-03 12:16

I want to perform a cartesian product between two SELECT statements as

SELECT 1, 2     INNER JOIN     SELECT 3, 4 ;

I expect the result to

5条回答
  •  忘掉有多难
    2020-12-03 12:52

    select v1, v2
    from
      (select 1 as v1 union
       select 2) t1,
      (select 3 as v2 union
       select 4) t2
    

    or even simpler:

    select *
    from
      (select 1 union
       select 2) t1,
      (select 3 union
       select 4) t2
    

提交回复
热议问题