[英]How to insert multiple rows from a table to another table based on date condition (PHP-MySQL-Query)?
如示意圖所示,我有兩個表。 我想從table1
三列URI
, fields
和details
中復制數據,如果table1
日期大於table2
月11日,則將它們插入到table2
中。 如下查詢:
INSERT INTO table2 (all_links, fields_one, fields_two) FROM table1 (URI, fields, details) WHERE date>"12-11-2013 00-00-00";
您能幫忙解決這個問題嗎?
做喜歡
INSERT INTO table2 (all_links, fields_one, fields_two)
select URI, fields, details FROM table1
WHERE date > "12-11-2013 00-00-00";
如果表位於不同的數據庫中(假設dbo
是默認所有者)
INSERT INTO DB1.dbo.table2 (all_links, fields_one, fields_two)
select URI, fields, details FROM DB2.dbo.table1
WHERE date > "12-11-2013 00-00-00";
嘗試這樣的事情:
INSERT INTO tbl_temp2 (fld_id)
SELECT tbl_temp1.fld_order_id
FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;
並檢查文檔:
http://dev.mysql.com/doc/refman/5.1/zh-CN/insert-select.html
INSERT INTO table2 (all_links, fields_one, fields_two) select URI, fields, details from table1 where date>"12-11-2013 00-00-00";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.