android - 来自不同表的联合列值

标签 android sql android-sqlite

我有三个表:Table1Table2Table3
这三个表都包含一个键 Column 作为外键。

我想要一个 SQLite 查询来返回所有三个表中所有不同的键列。

例如

表 1:

+---------+---------+
|  Col1   |  Col2   | key |
+---------+---------+
| Val 1   | Val 2   | 100 |
| Val 3   | Val 6   | 101 |
| Val 4   | Val 7   | 103 |
| Val 5   | Val 8   | 104 |
+---------+---------+

表 2:

+---------+---------+
|  Col1   |  Col2   |       key |
+---------+---------+
| Val 1   | Val 2   |       100 |
| Val 3   | Val 6   |       101 |
| Val 4   | Val 7   |       105 |
| Val 50  | Val 18  |       106 |
+---------+---------+

所以我想要 SQLite 查询以排序的顺序从两个表中返回所有不同的键

最佳答案

这应该适合你:

select key from table1  union select key from table2;

如果你想要重复使用union all

select key from table1  union all select key from table2;

关于android - 来自不同表的联合列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31428534/

相关文章:

android - Calabash-android:应用程序打开浏览器,我再也无法获取它

android - AsyncTaskLoader vs AsyncTask 用于在编辑单个实体 Activity 中加载单个实体?

android - 创建 Android 应用程序测试版本的推荐方法

java - IllegalArgumentException:列 _id 不存在

mysql - SQL:最大发生次数语句上的内连接

sql - 修改前序树遍历 : Selecting nodes 1 level deep

sql - 违反唯一键约束时的主键标识值增量

android - 与不是主键的列建立关系

java - 编译 : near "=": syntax error (code 1): , WHERE _id = 时出现 SQLite 异常 : UPDATE person_table SET person_name=?

java - 一种在设备上保存 Arraylist 的方法?