Reputation: 691
I have a query that is working fine, it creates one MySQL table from another based on selected fields.
My problem is I also want 2 new empty columns in the new table.
How do I create a new table based on an existing table, but with added empty columns?
$result = mysqli_query($mysqli,"CREATE TABLE matchstats SELECT hometeam, fthg, awayteam, ftag FROM results");
if (!$result) {
die("Query to create table failed");
}
Upvotes: 0
Views: 261
Reputation: 2565
You can try this
CREATE TABLE table2 (
new_column1 DECIMAL(5,2),
new_column2 DECIMAL(5,2)
) SELECT * FROM table1 ;
Upvotes: 3
Reputation: 243
First You can create new table from existing table. Below query is for that
create table `matchstats` AS Select * from `results`
Then you can add whatever columns you want into new table. Below query for that
ALTER TABLE `matchstats`
ADD DateOfBirth date
Upvotes: 0