How to Compare Rows in SQL?

Help copy table rows (sql)?

  • I need help, I have a table name 'c' If row hace a parent, means the id of the parents is the parentid.. and so on id |parentid| content ---------------------- 1 | | A 2 | | B 3 | 1 | C 4 | 1 | D 5 | 3 | E 6 | 5 | F I want to copy that rows to the same table 'c' without messing up the connection between id and parent id so its become.. for example: id |parentid| content ---------------------- 13 | | A 14 | | B 15 | 13 | C 16 | 13 | D 17 | 15 | E 18 | 17 | F Can you help me? I can use PHP if not possible with single sql query. Thanks.

  • Answer:

    insert into c values (int, int, varchar) select id + 20, parentid, content from c where id < 10; I've used 10 as the number to check on - examine max(id) to find out what value it should be. The increment (I've used 20) can be any number that doesn't violate id (I'm assuming id is a primary key).

ask_my_g... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

So for example your code for inserting your row is: Insert into table c (as c is the name of your table) values (Here you put whatever values you need. 1 set of values for each column following the law of the column. i.e. varchar, int, ect) then you execute that however many time you want them values in the one table i.e. if you want 3 rows with that exact info you high light that code then hit 'execute' or 'Ctrl + E' 3 times to insert 3 times Hope This Helps

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.