In MySQL, I would like to create a new table with all the information in this query:
select * into consultaa2 from SELECT CONCAT( 'UPDATE customers SET customers_default_address_id= ', (SELECT a.address_book_id FROM address_book a where c.customers_id=a.customers_id order by address_book_id desc limit 1), ' WHERE customers_id = ', customers_id, ';') AS sql_statement FROM customers c where c.customers_id > 3894;
The query is too long for the browser to show the concat and I need this to make this updates.
A copy of an existing table can be created using a combination of the CREATE TABLE statement and the SELECT statement. The new table has the same column definitions. All columns or specific columns can be selected.
On the Design tab, in the Query Type group, click Make Table. The Make Table dialog box appears. In the Table Name box, enter a name for the new table. Click the down-arrow and select an existing table name.
Question: How can I create a SQL table from another table without copying any values from the old table? Answer: To do this, the SQL CREATE TABLE syntax is: CREATE TABLE new_table AS (SELECT * FROM old_table WHERE 1=2);
You can do it like this:
CREATE TABLE tablename SELECT * FROM othertable;
tablename
is the name of the new table you want to create, SELECT * FROM othertable
is the query that returns the data the table should be created from.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With