Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这肯定是一个简单的问题,但我无法修复 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
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;