内部联接没有匹配的列

时间:2018-08-18 00:48:50

标签: mysql sql

我有下表,需要以下输出-

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 个答案:

答案 0 :(得分:2)

您不希望使用join。您要union all

select doctor as name, 'doctor' as occupation
from t
union all
select professor as name, 'professor' as occupation
from t;

答案 1 :(得分:0)

select
  doctor as name,
  'doctor' as occupation
from
  tb1
union all
select
  professor as name,
  'professor' as occupation
from
  tb1;