How to combine data into a temporary table in Mysql

岁酱吖の 提交于 2019-12-10 20:09:43

问题


I have a very large table called paypal_ipn_orders. In this table I have 2 important bits of information a row called item_name and a row called sort_num. I want to use certain parameters to pull out records from paypal_ipn_orders and put them into a temporary table called temp_table. I know how to select the records as follows

SELECT `item_name`, `sort_num` 
FROM `paypal_ipn_orders`
WHERE `packing_slip_printed` = 0
AND LOWER(`payment_status`) = `completed`
AND `address_name` <> ''

That query selects all the records I want to move to the temporary database I just don't know how to do that.


回答1:


Use MySQL's Insert Into Select I added generic data types to the columns in the temp table, you'll want to find out what the actual data types are from your table and make them the same.

CREATE TEMPORARY TABLE temp_table (
    item_name varchar(50), 
    sort_num int
);

INSERT INTO temp_table (item_name, sort_num)
SELECT `item_name`, `sort_num` 
FROM `paypal_ipn_orders`
WHERE `packing_slip_printed` = 0
AND LOWER(`payment_status`) = `completed`
AND `address_name` <> ''


来源:https://stackoverflow.com/questions/11993837/how-to-combine-data-into-a-temporary-table-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!