Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sqlite 基于select查询的输出联接表_Sqlite - Fatal编程技术网

Sqlite 基于select查询的输出联接表

Sqlite 基于select查询的输出联接表,sqlite,Sqlite,我尝试了下面的方法,但得到了错误的结果 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=

我尝试了下面的方法,但得到了错误的结果

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
选项卡1和选项卡2的预期连接结果

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

感谢您的帮助。

加入表并应用
where
子句中的条件:

select t1.id_1, t2.id_3, t2.name 
from tab_1 t1 inner join tab_2 t2
on t2.id_3 = t1.id_1 
where t1.id_1 = t1.id_2
请参阅。
结果:

解决了

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

下部(ids) 上部(ids)


谢谢你。但这是一个简单的联接,而不是带有子查询的联接。在我的例子中,我必须基于特定的输出加入,并且只使用where条件是没有帮助的。您的查询并不像您在这里看到的那样好:它不会返回您发布的预期结果。此外,您的查询甚至不会在其他数据库中运行,请选中此项:因为您的子查询返回的行数超过1行,并且不能与
=
一起使用。查看我的答案中的演示,了解为什么我的查询会返回您预期的结果。在中使用的=旁边,并调整了我选择的第一列。但正如我所说,输出是区分大小写的,这是我的主要问题。结果是4行,而不是2行。只有两行是我的输出。按小提琴上的按钮。结果是4行都具有id_3='ab01'
| id_1 | id_3 | name |
| ---- | ---- | ---- |
| ab01 | ab01 | test |
| ab02 | ab02 | test |
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)