MySQL Union - NULL为var?

时间:2011-11-13 14:45:37

标签: mysql union

查看此查询示例:

(SELECT fistName, middleName, lastName
FROM a)
UNION
(SELECT fistName, NULL as middleName, lastName
FROM b)

这样可以正常工作吗?表b根本没有中间名列...我想如果它不能正常运行,我总是可以试试这个:

'' as middlename

...谢谢

1 个答案:

答案 0 :(得分:2)

当然可行。此外,您不需要使用as middleName

(SELECT fistName, middleName, lastName
FROM a)
UNION
(SELECT fistName, NULL, lastName
FROM b)