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
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
Related Q & A:
- How can I optimize this dynamic SQL query in oracle with PL/SQL?Best solution by docs.oracle.com
- How to add primary key from multiple table as a foreign key in a table in sql server 2008?Best solution by stackoverflow.com
- What is Hash Table, how to create a hash table?Best solution by Stack Overflow
- How to insert into table in XML which has more than table?Best solution by Stack Overflow
- Can you help me learn how to copy and paste an html link to my website?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.