Java Android数据库的组合查询
我有一个连接查询,可以从三个表中查找数据,所以如何知道数据是从哪个表中创建的Java Android数据库的组合查询,java,android,sqlite,Java,Android,Sqlite,我有一个连接查询,可以从三个表中查找数据,所以如何知道数据是从哪个表中创建的 select text from table1 where title ='Vishal' union all select text from table2 where title ='Vishal' union all select text from table3 where title ='Vishal' 此查询为我提供了所需的输出,但我想知道 标题匹配从哪个表和我想得到的表名这不是一个聪明的解决方案,但
select text from table1 where title ='Vishal' union all select text from table2 where title ='Vishal' union all select text from table3 where title ='Vishal'
此查询为我提供了所需的输出,但我想知道标题匹配从哪个表和我想得到的表名这不是一个聪明的解决方案,但是怎么样
select text as text1, null as text2, null as text3 from table1 where title ='Vishal'
union all
select null as text1, text as text2, null as text3 from table2 where title ='Vishal'
union all
select null as text1, null as text2, text as text3 from table3 where title ='Vishal'
// Run your sql query
for (results){
if (results[i].text1 != null){
// match table1
}
else if (results[i].text2 != null){
// match table2
}
else if (results[i].text3 != null){
// match table3
}
}
可以向结果中添加具有常量值的列:
select text, 'table1' as source from table1 where title ='Vishal'
union all
select text, 'table2' from table2 where title ='Vishal'
union all
select text, 'table3' from table3 where title ='Vishal'
你需要更清楚地回答你的问题。您的答案可以是联合、联接、子查询或其他。没有足够的信息。详细描述这三个表的模式以及您想要做的事情。您可以用数据返回一些提示来识别,并用一些示例简要说明您的问题现在感觉舒服了吗?