gpt4 book ai didi

mysql选择两个不同的查询

转载 作者:行者123 更新时间:2023-11-29 08:01:36 32 4
gpt4 key购买 nike

我正在寻求有关公式的帮助。我正在寻找如何执行两个单独的 SELECT 查询,但不合并它们。

SELECT basetype from table1 where name="test";
**SELECT itemid from table2 where itemid="5";**

我希望查询将基本类型显示为一列,将 itemid 显示为另一列。简短版本是在显示结果的一个查询中进行两次选择。表之间的数据不必匹配。

编辑:我搞砸了。这是两张独立的 table 。我想要的结果基本上就是这样。

没有工会。

BASETYPE | ITEMID
1 | 5

最佳答案

我怀疑你想要这个:

select rn, max(basetype) as basetype, max(itemid) as itemid
from ((SELECT @rn := @rn + 1 as rn, basetype, NULL as itemid
from table1 cross join
(select @rn := 0) var
where name = 'test'
) union all
(SELECT @rn2 := @rn2 + 1, NULL, itemid
from table2 cross join
(select @rn2 := 0) var
where itemid = '5'
)
) t
group by rn;

关于mysql选择两个不同的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23662701/

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