gpt4 book ai didi

android - SQLite 联合列

转载 作者:行者123 更新时间:2023-11-30 02:57:42 26 4
gpt4 key购买 nike

我的问题

我实际上正在为 Android 应用程序开发 SQLite 数据库。我来自 MySQL,我将在其中公开的查询运行良好。

这是我的数据库结构:

table1: mid int(1) 主键自增,name varchar(256)

table2: aid int(1) primary key autoincrement, name varchar(256)

插入数据:

表 1,行 1:1,“abc”

表 2,行 1:1,“def”


我想做什么

我想做一个联合,这样得到的数据是:

| mid | aid | name |
--------------------
| 1 | 0 |"abc" |
| 0 | 1 |"def" |

所以,我想到了这个简单的查询:

select mid, name, 0 as aid from table1 union select aid, name, 0 as mid from table2;

但是,我得到了这个:

| mid | name | aid |
--------------------
| 1 |"abc" | 0 |
| 1 |"def" | 0 |

(我不介意列顺序)

这当然不是我要找的,我也看不出我做错了什么。

我们将不胜感激。

谢谢。

最佳答案

也许是列顺序出了问题?

怎么样

select mid, 0 as aid, name from table1 union select 0 as mid, aid, name from table2;

对我有用,至少在 SQLFiddle 上是这样:http://sqlfiddle.com/#!2/157f09/1

关于android - SQLite 联合列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23021777/

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