【发布时间】:2012-12-06 18:41:42
【问题描述】:
这肯定是一个简单的问题,但我无法修复 MySQL 查询: 我想在准备好的查询下面运行
select id from table1 where c_id = :c_id
union
select id,name from table2 where c_id = :c_id and temp = :temp
所以我在每个表选择的输出中有不同数量的列。这是它不工作的原因吗?
【问题讨论】:
这肯定是一个简单的问题,但我无法修复 MySQL 查询: 我想在准备好的查询下面运行
select id from table1 where c_id = :c_id
union
select id,name from table2 where c_id = :c_id and temp = :temp
所以我在每个表选择的输出中有不同数量的列。这是它不工作的原因吗?
【问题讨论】:
您可以在第一个查询中SELECT 一个文字值,如下所示:
SELECT id, 'no name' AS "name" FROM table1 WHERE c_id = :c_id
UNION ALL
SELECT id, name FROM table2 WHERE c_id = :c_id
AND temp = :temp;
【讨论】: