Suppose there are two fields exactly consistent with the table, Table1 and table2. Fields are password, username, email.
The basic method for multiple table queries using union (or union All) is a simple connection:
SELECT Password,username,email
From
Table1
where username like ' 123 '
UNION ALL//or union to remove duplicate data
SELECT Password,username,email
From
Table2
where username like ' 123 '
However, if the table differs from the table's fields, there is overlap but not exactly the same. It is not simply a union to connect.
To union two or more tables, the conditions that must be met are the same fields for those tables. To satisfy this condition, you can use "," instead of the missing field.
For example, there is a field password,username in the Table1 field password,username,email,ip;table2. The Query method is as follows:
/**
* MySQL Union
* Coder:xiaohudie
* 2015
*/
SELECT Password,username,email,ip
From
Table1
where username like ' 123 '
UNION All
SELECT password,username, ', ', ', '
From
Table2
where username like ' 123 '
Analogy
--
PS: Sorry everyone, I withdrew the comment reply email notification function, I hope to know.
Because the SMTP plug-in left a mailbox password in the database poses a certain risk. As for why it is dangerous, cough, ask me a close friend.