MySql : 3.23 이상사용가능,
- 단순히 다른테이블의 컬럼만 가져와서 업데이트 가능
- 특정값은 지정된값을 사용하고, 다른테이블의 특정컬럼값만 가져와서 업데이트 가능
==> INSERT INTO `_test`
(time,val1,val2,total)
SELECT NOW(),$_POST['val1'],$_POST['val2'], sum(total)
FROM
`_test` WHERE val1 < 100
=====================================================================================
http://dev.mysql.com/doc/refman/4.1/en/insert-select.html
INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
[INTO]
tbl_name[(col_name,...)]SELECT ...
[ ON DUPLICATE KEY UPDATE
col_name=expr, ... ]
With INSERT ... SELECT, you can quickly insert
many rows into a table from one or many tables. For example:
INSERT INTO tbl_temp2 (fld_id)
SELECT tbl_temp1.fld_order_id
FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;
The following conditions hold for a INSERT ...
SELECT statements:
-
Prior to MySQL 4.0.1,
INSERT ... SELECTimplicitly operates inIGNOREmode. As of MySQL 4.0.1, specifyIGNOREexplicitly to ignore rows that would cause duplicate-key violations. -
DELAYEDis ignored withINSERT ... SELECT. -
Prior to MySQL 4.0.14, the target table of the
INSERTstatement cannot appear in theFROMclause of theSELECTpart of the query. This limitation is lifted in 4.0.14. In this case, MySQL creates a temporary table to hold the rows from theSELECTand then inserts those rows into the target table. However, it remains true that you cannot useINSERT INTO t ... SELECT ... FROM twhentis aTEMPORARYtable, becauseTEMPORARYtables cannot be referred to twice in the same statement (see Section A.1.7.3, “TEMPORARY TABLEProblems”). -
AUTO_INCREMENTcolumns work as usual. -
To ensure that the binary log can be used to re-create the original tables, MySQL does not allow concurrent inserts for
INSERT ... SELECTstatements. -
Currently, you cannot insert into a table and select from the same table in a subquery.
-
To avoid ambigious column reference problems when the
SELECTand theINSERTrefer to the same table, provide a unique alias for each table used in theSELECTpart, and qualify column names in that part with the appropriate alias.
In the values part of ON DUPLICATE KEY UPDATE, you
can refer to columns in other tables, as long as you do not use GROUP BY in the SELECT part. One
side effect is that you must qualify non-unique column names in the values part.
'프로그램.코딩' 카테고리의 다른 글
| 서버시간표시, 서버타임기준으로 Client 컴에 시간표시하기 (0) | 2007.12.18 |
|---|---|
| JW FLV player (0) | 2007.12.03 |
| Oracle 페이징,리스팅,인덱스 (0) | 2007.10.22 |
| Snoopy 소켓 클래스 라이브러리 (0) | 2007.09.20 |
| 플래시8을 이용한 업로더.. (0) | 2007.09.03 |
댓글