Jump to content


Photo

Merging two SQL result tables that have the same fields


  • Please log in to reply
2 replies to this topic

#1 mokahola

mokahola
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 August 2006 - 02:15 PM

Hi,

I have two tables, one for patches and one for mods, I want to merge these into one table.  Each has the same structure, as follows:

+-----------+-----------+-----------+
| name        | adddate    | views      |
+-----------+-----------+-----------+
|<name>    | <date>      | <views>  |
|<name>    | <date>      | <views>  |
+-----------+-----------+-----------+

Now I want to combine them so that all the information is in one table, so I can order them by the adddate, and that the names of the patches and the names of the mods are in the same [name] column. The same goes for the other columns.

I searched the internet and couln't find any thing about it, so maybe it isn't even possible.

Thanks in advance.

mokahola.

#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 22 August 2006 - 03:28 PM

INSERT INTO table1
SELECT *
FROM table2

Rename table1/table2 appropriately.
table2 is the second table you want to merge with table 1.
Then empty table2 and delete it.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#3 mokahola

mokahola
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 August 2006 - 03:44 PM

thnx, but I didn't want it in there permenently, but I fond a way:

SELECT * FROM mods
UNION ALL
SELECT * FROM patches ORDER BY adddate




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users