Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.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
Android 单表上的简单SQL查询_Android_Mysql_Sql_Sqlite_Android Sqlite - Fatal编程技术网

Android 单表上的简单SQL查询

Android 单表上的简单SQL查询,android,mysql,sql,sqlite,android-sqlite,Android,Mysql,Sql,Sqlite,Android Sqlite,我很惭愧,但我必须问这个SQL问题。我实际上是在Android上使用SQLITE 假设只有一个表有两列 USER1 USER2 111 555 111 300 445 111 555 111 325 111 111 233 300 111 我希望得到以下结果: USER1 USER2 111 300 111 555 我尝试了internaljoin和INTERSECT,但无法使其工作 非常感谢 看起来您希望在表中还存在切换的user1/user2的行。还

我很惭愧,但我必须问这个
SQL
问题。我实际上是在
Android
上使用
SQLITE

假设只有一个表有两列

USER1 USER2 
111   555
111   300
445   111
555   111
325   111
111   233
300   111
我希望得到以下结果:

USER1 USER2
111   300
111   555
我尝试了
internaljoin
INTERSECT
,但无法使其工作


非常感谢

看起来您希望在表中还存在切换的user1/user2的行。还有user1
select t1.user1, t1.user2
from table t1
join table t2 on t1.user1 = t2.user2 and t1.user2 = t2.user1
where t1.user1 <= t1.user2
选择t1.user1、t1.user2
来自表t1
在t1.user1=t2.user2和t1.user2=t2.user1上联接表t2

其中t1.user1请将您的查询添加到您的问题中。
我尝试了内部联接和相交
显示代码。请解释获取这两行而不是其他行的逻辑。您完全正确。我很抱歉没有添加我的代码,也没有以更好的方式解释我想要实现的目标@arlh解决了我的问题。@jarlh你应该接受这个答案。@IntelliJAmiya,是jennie788问的问题。@jarlh非常感谢你!!!你的回答解决了我的问题。我的问题是我使用了:t1.user1=t2.user2上的联接表t2,而不是您编写的:t1.user1=t2.user2和t1.user2=t2.user1上的联接表t2