I want to create a table_b which shares some fields in common with an existing table_a, but also has some unique fields of its own. I want to copy the data from table_a into table_b for the fields that they share in common, while leaving table_b's unique fields blank. Can I do this in a single CREATE statement, or will it take a couple of statements. Either way, please show me the proper syntax for this. Thanks!
You want to use a 'SELECT INTO' query. Here's a link explaining it: http://www.w3schools.com/sql/sql_select_into.asp That will make a copy of your table, from there you go into the sturcture and add the additional fields you want.
or you can use a query in the following format. But if the fields are different, it would be difficult. INSERT INTO 'databasename'.'tablename' (SELECT * FROM 'databasename'.'tablename'); Or else, make a copy of the database with another name and add extra fields to it.
Why would you want to copy and dupliate data ? Is it not an option to keep table_b entirely unique with its own fields and simply JOIN with table_a when you also need the fields from that table.
hello, You can use this sql syntex to copy the data for backup to another file SELECT * INTO new_table_name [IN externaldatabase] FROM old_tablename
I wanted a table to would keep a list of all users that have ever been registered on the website, even if the administrator deleted users from the jos_users table. Found a solution afterwords: INSERT INTO jos_users_copy (id, username, email, block, usertype) SELECT jos_users.id, jos_users.username, jos_users.email, jos_users.block, jos_users.usertype FROM jos_users Code (markup):
we can use the two table witout copy or we can copy the structure of the table or we apply the query for it