-3

I need SQL command that will insert a row after specific row. Example:-

Before table

Id.         Name.      
1.           Xyz.          
2.           Xyz
3.           Xyz    

Want result need to add 'Abc' data after each 'xyz' having same id like:-

Id.         Name.      
1.           Xyz.    
2.           Xyz
3.           Xyz
1.           Abc
2.           Abc
3.           Abc

Note this command work on 1000 data

Nick
  • 138,499
  • 22
  • 57
  • 95
  • 2
    There is no such thing as "after" in a table. Tables represent *unordered* sets. – Gordon Linoff Mar 22 '19 at 12:07
  • Possible duplicate of [Need SQL command that will insert a row after specific row](https://stackoverflow.com/questions/55122499/need-sql-command-that-will-insert-a-row-after-specific-row) – jmarkmurphy Mar 22 '19 at 20:57
  • Really, you should have provided feedback on your other question instead of asking it a second time. – jmarkmurphy Mar 22 '19 at 20:58

1 Answers1

0

Try using an INSERT INTO ... SELECT:

INSERT INTO yourTable (id, name)
SELECT id, 'Abc'
FROM yourTable
WHERE name = 'Xyz';

This assumes that you only want to duplicate rows having Xyz as the name. If you instead want to duplicate every record with an Abc version, then just remove the WHERE clause.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360