sqlite合并从多个列中全选 [英] sqlite combine select all from multiple columns

查看:163
本文介绍了sqlite合并从多个列中全选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在SQLite中将许多选择查询组合成1条语句?

How to combine many select queries into 1 statement in SQLite?

SELECT * FROM Table1 WHERE condition1
SELECT * FROM Table2 WHERE condition2
SELECT * FROM Table3 WHERE condition3
...

推荐答案

使用UNION组合三个查询的结果.

Use UNION to combine the results of the three queries.

UNION将删除重复项,并保留在最终结果的唯一行上.如果要保留重复的行,请使用UNION ALL.

UNION will remove duplicate leaving on unique rows on the final result. If you want to keep the duplicate rows, use UNION ALL.

SELECT * FROM Table1 WHERE condition1 
UNION
SELECT * FROM Table2 WHERE condition2 
UNION
SELECT * FROM Table3 WHERE condition3

caveat :每条选择语句上的列数(以及数据类型)必须匹配.

caveat: the number of columns (as well as the data type) must match on each select statement.

更新1

根据您在下面的评论,您正在寻找JOIN

based on your comment below, You are looking for JOIN,

SELECT  a.*, b.*, c.*
FROM    table1 a
        INNER JOIN table2 b
            ON a.ColName = b.ColName
        INNER JOIN table3 c
            ON a.ColName = c.ColName
-- WHERE    .. add conditions here ..

要进一步获得有关联接的知识,请访问下面的链接:

To further gain more knowledge about joins, kindly visit the link below:

这篇关于sqlite合并从多个列中全选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆