简体   繁体   English

sqlite合并从多个列中全选

[英]sqlite combine select all from multiple columns

How to combine many select queries into 1 statement in SQLite? 如何在SQLite中将许多选择查询合并为1条语句?

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

Use UNION to combine the results of the three queries. 使用UNION合并三个查询的结果。

UNION will remove duplicate leaving on unique rows on the final result. UNION将删除重复项,并保留在最终结果的唯一行上。 If you want to keep the duplicate rows, use UNION ALL . 如果要保留重复的行,请使用UNION ALL

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

caveat : the number of columns ( as well as the data type ) must match on each select statement. 警告 :在每个select语句上,列数( 以及数据类型 )必须匹配。

UPDATE 1 更新1

based on your comment below, You are looking for JOIN , 根据下面的评论,您正在寻找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: 要进一步获得有关联接的知识,请访问以下链接:

您也可以查询SELECT * FROM bday>'1970-05-20'的用户UNION ALL SELECT * FROM bday <'1970-01-20'的用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM