代码之家  ›  专栏  ›  技术社区  ›  user1050619

内部联接没有匹配的列

  •  0
  • user1050619  · 技术社区  · 6 年前

    doctor professor <--column names
    tom    mary
    harry  layla
    

    enter image description here

    这是我的问题,不起作用-

    select tb1.name, tb2.name from 
    (
    select name
    from tutorials.occupations
    where occupation = 'doctor'
    order by name
    ) tb1
    inner join
    (
    select name
    from tutorials.occupations
    where occupation = 'professor'
    order by name
    ) tb2
    on tb1.name = tb2.name
    
    2 回复  |  直到 6 年前
        1
  •  2
  •   Gordon Linoff    6 年前

    你不想 join . 你想要的 union all :

    select doctor as name, 'doctor' as occupation
    from t
    union all
    select professor as name, 'professor' as occupation
    from t;
    
        2
  •  0
  •   Bhargav Kothadia    6 年前
    select
      doctor as name,
      'doctor' as occupation
    from
      tb1
    union all
    select
      professor as name,
      'professor' as occupation
    from
      tb1;