Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to insert same record multiple times in Mysql using single query and not using for loop.

How to insert same record multiple times in Mysql using single query and not using for loop.

Scheduled Pinned Locked Moved Database
databasemysqltutorial
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sr159
    wrote on last edited by
    #1

    Hi I created one web form and i need to insert all same record more than 10 times using Mysql query. How to insert same record multiple times in Mysql using single query and not using for loop. If anybody knows, please reply me. one more thing in Sybase some people sujjesting to go for GO command like insert into tablename(columnname) values('abc') go 50 it wil insert 50 records like this is there any chance to write Mysql query to insert 50 records using Go command like that, i tried but it is not working Thanking you,

    P S J D S 6 Replies Last reply
    0
    • S sr159

      Hi I created one web form and i need to insert all same record more than 10 times using Mysql query. How to insert same record multiple times in Mysql using single query and not using for loop. If anybody knows, please reply me. one more thing in Sybase some people sujjesting to go for GO command like insert into tablename(columnname) values('abc') go 50 it wil insert 50 records like this is there any chance to write Mysql query to insert 50 records using Go command like that, i tried but it is not working Thanking you,

      P Offline
      P Offline
      phil o
      wrote on last edited by
      #2

      Your question doesn't really make any sense. Why don't you want to use a for loop ? You can always issue 10+ same statements to do your insert, but then what's the point to do it this way ?

      No memory stick has been harmed during establishment of this signature.

      S 1 Reply Last reply
      0
      • S sr159

        Hi I created one web form and i need to insert all same record more than 10 times using Mysql query. How to insert same record multiple times in Mysql using single query and not using for loop. If anybody knows, please reply me. one more thing in Sybase some people sujjesting to go for GO command like insert into tablename(columnname) values('abc') go 50 it wil insert 50 records like this is there any chance to write Mysql query to insert 50 records using Go command like that, i tried but it is not working Thanking you,

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        with out knowing what you code is like and how you are inserting your data have you considered a union statement? MySQL Union[^]

        Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

        1 Reply Last reply
        0
        • P phil o

          Your question doesn't really make any sense. Why don't you want to use a for loop ? You can always issue 10+ same statements to do your insert, but then what's the point to do it this way ?

          No memory stick has been harmed during establishment of this signature.

          S Offline
          S Offline
          sr159
          wrote on last edited by
          #4

          in Sybase some people sujjesting to go for GO command like insert into tablename(columnname) values('abc') go 50 it wil insert 50 records like this is there any chance to write Mysql query to insert 50 records using Go command like that, i tried but it is not working

          1 Reply Last reply
          0
          • S sr159

            Hi I created one web form and i need to insert all same record more than 10 times using Mysql query. How to insert same record multiple times in Mysql using single query and not using for loop. If anybody knows, please reply me. one more thing in Sybase some people sujjesting to go for GO command like insert into tablename(columnname) values('abc') go 50 it wil insert 50 records like this is there any chance to write Mysql query to insert 50 records using Go command like that, i tried but it is not working Thanking you,

            J Offline
            J Offline
            Jorgen Andersson
            wrote on last edited by
            #5

            It sounds like your database is in serious need of normalization.

            Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

            1 Reply Last reply
            0
            • S sr159

              Hi I created one web form and i need to insert all same record more than 10 times using Mysql query. How to insert same record multiple times in Mysql using single query and not using for loop. If anybody knows, please reply me. one more thing in Sybase some people sujjesting to go for GO command like insert into tablename(columnname) values('abc') go 50 it wil insert 50 records like this is there any chance to write Mysql query to insert 50 records using Go command like that, i tried but it is not working Thanking you,

              S Offline
              S Offline
              Simon_Whale
              wrote on last edited by
              #6

              MySql Insert documentation[^] As far as I can see you will need to use a loop of some kind, can I ask why you want to do it with no looping? you could easily do it simply like this in psuedo code

              Open Database Connection
              For i = 1 to 50
              Insert into Datbase table the values
              i++
              next
              Close Database

              As others have said you may need to reconsider your database design.

              Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

              S 1 Reply Last reply
              0
              • S Simon_Whale

                MySql Insert documentation[^] As far as I can see you will need to use a loop of some kind, can I ask why you want to do it with no looping? you could easily do it simply like this in psuedo code

                Open Database Connection
                For i = 1 to 50
                Insert into Datbase table the values
                i++
                next
                Close Database

                As others have said you may need to reconsider your database design.

                Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

                S Offline
                S Offline
                sr159
                wrote on last edited by
                #7

                by using for loop i can but is there any possibility to write a single Mysql query to insert 50 or more records. In Sybase they are using GO command like insert into tablename(columnname) values('abc') go 50 it wil insert 50 records.

                S 1 Reply Last reply
                0
                • S sr159

                  by using for loop i can but is there any possibility to write a single Mysql query to insert 50 or more records. In Sybase they are using GO command like insert into tablename(columnname) values('abc') go 50 it wil insert 50 records.

                  S Offline
                  S Offline
                  Simon_Whale
                  wrote on last edited by
                  #8

                  The only way I could see you doing that in MySql is to do something like the following but I believe that it will be unmanageable and to be honest I personally only use this approach when I am trying to knock up some dirty data for R&D or testing never used it in a live system

                  insert into numbers (MyNumber)
                  select 1
                  union
                  select 2
                  union
                  select 3
                  union
                  select 4

                  Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

                  1 Reply Last reply
                  0
                  • S sr159

                    Hi I created one web form and i need to insert all same record more than 10 times using Mysql query. How to insert same record multiple times in Mysql using single query and not using for loop. If anybody knows, please reply me. one more thing in Sybase some people sujjesting to go for GO command like insert into tablename(columnname) values('abc') go 50 it wil insert 50 records like this is there any chance to write Mysql query to insert 50 records using Go command like that, i tried but it is not working Thanking you,

                    D Offline
                    D Offline
                    David Skelly
                    wrote on last edited by
                    #9

                    According to the MySQL documentation:

                    INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas. Example:

                    INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

                    1 Reply Last reply
                    0
                    • S sr159

                      Hi I created one web form and i need to insert all same record more than 10 times using Mysql query. How to insert same record multiple times in Mysql using single query and not using for loop. If anybody knows, please reply me. one more thing in Sybase some people sujjesting to go for GO command like insert into tablename(columnname) values('abc') go 50 it wil insert 50 records like this is there any chance to write Mysql query to insert 50 records using Go command like that, i tried but it is not working Thanking you,

                      S Offline
                      S Offline
                      SilimSayo
                      wrote on last edited by
                      #10

                      Why would you want to duplicate data this way?

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups