How to join results with UNION in MySQL?

The UNIONs were introduced in MySQL 4. The unions are useful if you wish to join the results from more than one query, but be aware that the number of the returned columns by each select query should be the same.
(as well as their type)
 
The very simple example below show you the basics of the UNION statement
 
SELECT id, name FROM my_table
UNION
SELECT id, name FROM my_table;

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Captcha
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
14 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.