Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here




   Misc

   Amazon

   Links

    


Insert....Select Syntax

 

INSERT [LOW_PRIORITY] [IGNORE] [INTO] tbl_name [(column list)] SELECT ...

With INSERT ... SELECT , you can quickly insert many rows into a table from one or many tables.

INSERT INTO tblTemp2 (fldID) SELECT tblTemp1.fldOrder_ID FROM tblTemp1 WHERE tblTemp1.fldOrder_ID > 100;

The following conditions hold for an INSERT ... SELECT statement:

  • Prior to MySQL 4.0.1, INSERT ... SELECT implicitly operates in IGNORE mode. As of MySQL 4.0.1, you should specify IGNORE explicitly to ignore records that would cause duplicate-key violations.
  • Do not use DELAYED with INSERT ... SELECT .
  • Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
  • AUTO_INCREMENT columns work as usual.
  • In C programs, you can use the C API function mysql_info() to get information about the query.
  • To ensure that the binary log can be used to re-create the original tables, MySQL will not allow concurrent inserts during INSERT ... SELECT .

You can use REPLACE instead of INSERT to overwrite old rows. REPLACE is the counterpart to INSERT IGNORE in the treatment of new rows that contain unique key values that duplicate old rows: The new rows are used to replace the old rows rather than being discarded.


 

 

back to MySQL reference


 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
Copy a file(VB)
a simple dialog box using swing(Java)
dial a number(VB)
Create a php file(C)
set background colour(CSS)
IP address logger(ASP)
hello world in java(Java)
Play a sound using API(VB)

    




Copyright © 2004 by programmershelp.co.uk