MySql INSERT -> SELECT statement
Ovo će biti jako korisno za obrade, molim Vas da
detaljno proučite kako ovo funkcioniše.
Poenta je da kreirate insert statement
kao neki select iz druge/iste tabele.
Koristan link je:
http://dev.mysql.com/doc/refman/5.0/en/
tamo se nalazi kompletna MYSQL dokumentacija.
radovan
INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
[INTO]tbl_name[(col_name,...)]
SELECT ...
[ ON DUPLICATE KEY UPDATEcol_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:
Specify
IGNOREto ignore rows that would cause duplicate-key violations.DELAYEDis ignored withINSERT ... SELECT.The target table of the
INSERTstatement may appear in theFROMclause of theSELECTpart of the query. (This was not possible in some older versions of MySQL.) 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 statementAUTO_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.
www.baco.co.yu
<< Home