根据我的理解"UNION中的每个SELECT语句必须具有相同的列数.列也必须具有相似的数据类型.此外,每个SELECT语句中的列必须具有相同的顺序." 那么,如果第一个SELECT的列数多于第二个可以生成的列数,那该怎么办?这就是我的意思:让我说我想
SELECT "City", "Country", "Continent" from table1
UNION
SELECT "City", "Country" from table2
Run Code Online (Sandbox Code Playgroud)
...假设表2不包含名为"Continent"的列,但是对于我的需要,来自table2的记录在该列中具有空白或NULL是正常的.我正在使用dashDB.
Tim*_*ter 23
您始终可以添加"虚拟"列:
SELECT "City", "Country", "Continent" from table1
UNION
SELECT "City", "Country", NULL AS "Continent" from table2
Run Code Online (Sandbox Code Playgroud)
您好,
您可以使用,
SELECT "City", "Country", "Continent" from table1
UNION
SELECT "City", "Country", ' ' as "Continent" from table2
Run Code Online (Sandbox Code Playgroud)
或者
SELECT "City", "Country", "Continent" from table1
UNION
SELECT
"City", "Country", NULL as "Continent" from table2
Run Code Online (Sandbox Code Playgroud)
它将表 2 中的“Continent”视为空