List:General Discussion« Previous MessageNext Message »
From:Roger Baklund Date:July 6 2002 12:34pm
Subject:Re: newbie mysql-SQL question
View as plain text  
* Laszlo G. Szijarto
> I'm trying to run two tables with identical table structures into a single
> continuous resultset.  To simpify, I have one table with columns
> ID int and
> NAME varchar(32) and another table2 with columsn ID int and NAME
> varchar(32), and each table has 100 items.  How would I formulate an SQL
> query to return 200 items in a continuous resultset which would have rows
> 1-100 from table and 101-200 from table2 -- making it appear in the
> resultset as if these were one continuous 200-item table.

Mysql version 4 have UNION support:

SELECT * FROM table_a
  UNION
SELECT * FROM table_b;

The above is _one_ statement.

<URL: http://www.mysql.com/doc/U/N/UNION.html >

Note the use of parentheses when you need to ORDER the combined result.

Version 3.23.x does not support UNION, but you can achieve the same result
using a temporary table, and three statements:

CREATE TABLE tmp SELECT * FROM table_a;
INSERT INTO tmp SELECT * FROM table_b;
SELECT * FROM tmp ORDER BY ID;

--
Roger

Thread
newbie mysql-SQL questionLaszlo G. Szijarto6 Jul
  • Re: newbie mysql-SQL questionRoger Baklund6 Jul