假设我有以下表格:
Name | Occupation
A
B
C
D
E
Workplace | Phone Number
A
B
C
我想执行选择以将表合并到一个表中:
MyName | Type
A | Person
B | Person
C | Person
D | Person
E | Person
A | Workplace
B | Workplace
C | Workplace
我该如何做到这一点?我试过了:
SET @a = 'Person'
SET @b = 'Name'
SELECT Name, @a FROM tablea
UNION
SELECT Workplace, @b FROM tableb
并且第二列中的输出似乎都是“Person”,并且没有“Workplace”。我究竟做错了什么?
或者有没有办法我可以从单个 SELECT 语句中获取以下内容:
MyName
A_Person
B_Person
C_Person
D_Person
E_Person
A_Workplace
B_Workplace
C_Workplace
注意:我正在使用 MySQL Workbench