Page 1 of 1

temporary table containing results from 2 static tables

Posted: Sat Feb 14, 2004 12:58 pm
by mis2o
hi, i need to create a temporary table which contains results from 2 static tables. i use this code, where $_SESSION['query_one'] and $_SESSION['query_two'] contain select query strings for table1 and table2:

Code: Select all

<?php
$joined_query = ($_SESSION['query_one'].";".$_SESSION['query_two']);
$temp_table_query = "CREATE TEMPORARY TABLE tmp $joined_query";
if (!mysql_query($temp_table_query, $connection)) { echo"<script>alert('Query failed')</script>"; }
?>
i always get "Query failed" when executing it, but when i run the $temp_table_query in PHPMyAdmin it works.
what is wrong? can i have 1 temp table containing 2 static tables at all?
if not why does it work in PHPMyAdmin?
thanx

Posted: Sat Feb 14, 2004 1:55 pm
by Weirdan
Are you looking for [mysql_man]UNION[/mysql_man]?

Posted: Sat Feb 14, 2004 2:36 pm
by mis2o
i read in mysql manual that UNION is implemented in MySQL 4 only. i use mysql 3.23.39 to develop becouse it runs on the server i write the application for. however, i think that the query1;query2 syntax should work but maybe it doesn't work with CREATE TABLE. don't you know of other way of working it around without using UNION?[/mysql_man]