gpt4 book ai didi

mysql - 具有不同列数的联合查询

转载 作者:行者123 更新时间:2023-11-29 02:30:31 25 4
gpt4 key购买 nike

这肯定是一个简单的问题,但我无法修复 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;

关于mysql - 具有不同列数的联合查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13951940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com