0

您好,我想执行更多 SQL 语句并得到一个结果,比如我有 3 个表,它们都有相同的列名:

Table user1
User Password Email

Table user2
User Password Email

Table user3
User Password Email

现在我想在一个 SQL 语句中从所有表中获取所有用户密码电子邮件。我希望你能帮助我。

感谢您的帮助。

4

5 回答 5

1

使用UNION.

SELECT User, PassWord, Email FROM Table1
UNION 
SELECT User, PassWord, Email FROM Table2
UNION 
SELECT User, PassWord, Email FROM Table3

上述查询将生成唯一记录。如果要保留重复,请添加ALL

SELECT User, PassWord, Email FROM Table1
UNION ALL
SELECT User, PassWord, Email FROM Table2
UNION ALL
SELECT User, PassWord, Email FROM Table3
于 2013-04-15T09:27:41.553 回答
1

Aunion将允许您合并记录集。

select user, password, email from user1
union 
select user, password, email from user2
union
select user, password, email from user3
于 2013-04-15T09:28:12.400 回答
1

很简单,使用 Union 运算符如下:

SELECT User, PassWord, Email FROM User1
UNION 
SELECT User, PassWord, Email FROM User2
UNION
SELECT User, PassWord, Email FROM User3
于 2013-04-15T09:31:07.057 回答
0
select User, Password, Email
from Table1
union all
select User, Password, Email
from Table2
union all
select User, Password, Email
from Table3
于 2013-04-15T09:27:41.743 回答
0

联合操作是您问题的一个很好的例子:

select user, password, email from user1
union
selection user, password, email from user2
union
select user, password, email from user3
于 2013-04-15T09:33:03.560 回答