Reputation: 149
Hello I would like to execute more SQL Statements and get one result like lets say I have 3 Tables they all have same Column Names:
Table user1
User Password Email
Table user2
User Password Email
Table user3
User Password Email
Now I want to get all User Password Emails from all the Tables in one SQL Statement. I hope you can help me.
Thank you for your help.
Upvotes: 0
Views: 73
Reputation: 123
Union operation is very good example for your question:
select user, password, email from user1
union
selection user, password, email from user2
union
select user, password, email from user3
Upvotes: 0
Reputation: 187
Quite simple, use Union operator as below :
SELECT User, PassWord, Email FROM User1
UNION
SELECT User, PassWord, Email FROM User2
UNION
SELECT User, PassWord, Email FROM User3
Upvotes: 1
Reputation: 94489
A union
will allow you to combine the record sets.
select user, password, email from user1
union
select user, password, email from user2
union
select user, password, email from user3
Upvotes: 1
Reputation: 41968
select User, Password, Email
from Table1
union all
select User, Password, Email
from Table2
union all
select User, Password, Email
from Table3
Upvotes: 0
Reputation: 263803
use UNION
.
SELECT User, PassWord, Email FROM Table1
UNION
SELECT User, PassWord, Email FROM Table2
UNION
SELECT User, PassWord, Email FROM Table3
The above query will generate unique records. If you want to keep duplicate, add ALL
SELECT User, PassWord, Email FROM Table1
UNION ALL
SELECT User, PassWord, Email FROM Table2
UNION ALL
SELECT User, PassWord, Email FROM Table3
Upvotes: 1