Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

Creating a table from a query in MySQL/PHP

0

40 views

I'm not sure this is possible, but the code I tried using first is:

mysql_query ("CREATE TABLE My_table as ( SELECT * FROM CPE LEFT JOIN Greenwich_j20 ON CPE.cust_index = Greenwich_j20.cust_index LEFT JOIN Liverpool_j20 ON CPE.cust_index = Liverpool_j20.cust_index)")
 or die ("this certainly didn't work\n");

The query itself works fine, and the syntax for the table works fine, but the combination is what it really doesn't like. Does it have a problem creating a table from a left join query?

asked April 12, 2011 11:26 am CDT
posted via StackOverflow

2 Answers

0
 

If there is any auto increment column in your existing tables that will be not remain auto_increment in the table to be created.

You could try by selecting columns instead of * there should be an error of column Ambiguous.

answered April 12, 2011 12:23 pm CDT
-1
 
<?php
// Make a MySQL Connection
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

// Create a MySQL table in the selected database
mysql_query("CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
 name VARCHAR(30), 
 age INT)")
 or die(mysql_error());  

echo "Table Created!";

?>

copy-pasted it from http://www.tizag.com/mysqlTutorial/mysqltables.php

answered April 12, 2011 12:23 pm CDT

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions
Three table query MySQL
January 13, 2011
Mysql two table query
December 30, 2010
Multi-table mysql query
February 22, 2011