I want to do something like this
Insert into abc(col1, col2, col3) select col1, 1, col3 from xyz where somecondition
Insert into abc(col1, col2, col3) select col1, 2, col3 from xyz where somecondition
Insert into abc(col1, col2, col3) select col1, 3, col3 from xyz where somecondition
Insert into abc(col1, col2, col3) select col1, 4, col3 from xyz where somecondition
...
So there is only second column value that is changing and all else are same.
Is there any better or compact way to do the above?
May be something in one query!
I am using MySql
Edit:
I am using this inside a stored procedure.
If
someconditionis the same and you need sequential numbers forcol2you can do following:UPDATE
If your
WHEREconditions applied toxyzensures that only one row will be returned and yourxyztable has more than 9 records (although you canCROSSwith any other table) you can leverageCROSS JOINANDLIMITto replicate your row N (9 in the example) times with singleINSERT-SELECTstatement like this: