首页 > 解决方案 > 根据选择查询的输出连接表

问题描述

我尝试了以下但得到了错误的结果。

select tab_2.id_3,tab_2.name from tab_2 where tab_2.id_3 in (select id_1 from tab_1 where id_1= id_2)

我正在寻找的是:

我有第一个表,我在其中提取了我想要的 id:

tab_1:
id_1 | id_2
ab01 | ab01
ab02 | ab02
ab03 | ab05
ab04 | ab09

Select id_1 from tab_1 where id_1= id_2
--id_1--
ab01
ab02

tab_2
id_3|name
ab01|test
ab02|test
ab07|test
ab06|test

来自 tab_1 和 tab_2 的预期连接结果

id_1 | id_3 | name
ab01 | ab01 | test
ab02 | ab02 | test

谢谢你的帮助。

标签: sqlite

解决方案


解决了!

我遇到的问题是输出。在一个表中,ID 是大写的,而在第二个表中,ID 是小写的。所以我将其中一个转换为小写或大写。

下(ids)上(ids)

图片展示

select tab_2.id_3,tab_2.name from tab_2 where tab_2.id_3 in (select id_1 from tab_1 where id_1= id_2)

推荐阅读