Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    SQL query to insert muliple records with different email address

    Hi guys.

    I have the following query

    PHP Code:
    INSERT INTO `cork_wall`.`Classified` (
    `
    id` ,
    `
    user` ,
    `
    description` ,
    `
    link` ,
    `
    img1` ,
    `
    published`
    )
    VALUES (
    NULL 'corkdjs@gmail.com''Hi guys.''''http://munsterweddingdjs.com/images/weddings-in-east-cork.jpg''0'
    ); 
    how do i insert the same record multiple times but changing the email address each time to the following emails...

    email1@hotmail.com
    email2@hotmail.com
    email3@hotmail.com etc

    is there any quick way of doing it besides writhing out a different query for each email address?
    Last edited by kevinkhan; 06-07-2011 at 08:23 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,458
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    The best you can do is provided by MySQL (only) via:

    Code:
    INSERT INTO table ( field1, field2, field3 )
    VALUES ( x, y, z ), ( a, b, c ), ( .... )
    That is, you simply repeat the insert values, in parens, once for each set of values you want to insert.

    I don't know of any other DB that allows this, so you are lucky you are using MySQL.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •