This is a discussion on Moving data from one table to another, (existing), one. within the MySQL forums, part of the Database Server Software category; --> Hi, I have a table, TABLEA ( ROWA[int], ROWB[int] ) and I want to move all the data to ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, I have a table, TABLEA ( ROWA[int], ROWB[int] ) and I want to move all the data to another table, TABLEB ( ROWA[int], ROWB[string], ROWC[string] ) ROWC will be a constant string but ROWB will be converted to a string (VARCHAR 255) of the current INT value. How would you move the data from A to B? INSERT INTO TABLEB ( ROWA, ROWB, ROWC ) VALUES ( SELECT ROWA, ROWB FROM TABLEA, 'ROWC'.... ) Not sure how that would work. Thanks FFMG -- 'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory' (http://www.webhostshunter.com/) | 'Recreation Vehicle insurance' (http://www.insurance-owl.com/other/car_rec.php) 'Free URL redirection service' (http://urlkick.com/) ------------------------------------------------------------------------ FFMG's Profile: http://www.httppoint.com/member.php?userid=580 View this thread: http://www.httppoint.com/showthread.php?t=17868 Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing). |
| |||
| On 27 Jun, 06:31, FFMG <FFMG.2st...@no-mx.httppoint.com> wrote: > Hi, > > I have a table, TABLEA ( ROWA[int], ROWB[int] ) and I want to move all > the data to another table, TABLEB ( ROWA[int], ROWB[string], > ROWC[string] ) > > ROWC will be a constant string but ROWB will be converted to a string > (VARCHAR 255) of the current INT value. > > How would you move the data from A to B? > > INSERT INTO TABLEB ( > ROWA, > ROWB, > ROWC > ) > VALUES > ( > SELECT ROWA, ROWB FROM TABLEA, > 'ROWC'.... ) > > Not sure how that would work. > > Thanks > > FFMG > > -- > > 'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory' > (http://www.webhostshunter.com/) | 'Recreation Vehicle insurance' > (http://www.insurance-owl.com/other/car_rec.php) > 'Free URL redirection service' (http://urlkick.com/) > ------------------------------------------------------------------------ > FFMG's Profile:http://www.httppoint.com/member.php?userid=580 > View this thread:http://www.httppoint.com/showthread.php?t=17868 > > Message Posted via the webmaster forumhttp://www.httppoint.com, (Ad revenue sharing). I assume you actually mean COLA, COLB, COLC as you are talking about columns and not rows. You also have to use the correct sytax as shown in the manual for INSERT ... SELECT http://dev.mysql.com/doc/refman/5.0/en/insert.html You would write it like this: INSERT INTO TABLEB ( ROWA, ROWB, ROWC ) SELECT ROWA, ROWB, 'ROWC' FROM TABLEA OR more correctly conceptwise: INSERT INTO TABLEB ( COLA, COLB, COLC ) SELECT COLA, COLB, 'COLC' FROM TABLEA |
| |||
| Captain Paralytic;78563 Wrote: > > ... > INSERT INTO TABLEB ( > COLA, > COLB, > COLC > ) > SELECT COLA, COLB, 'COLC' FROM TABLEA Thanks, you are right I was talking about COLA/B/C I just want to make sure that COLB will not be a problem as I am inserting an INT into a VARCHAR(255). I don't need to convert anything? FFMG -- 'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory' (http://www.webhostshunter.com/) | 'Recreation Vehicle insurance' (http://www.insurance-owl.com/other/car_rec.php) 'Free URL redirection service' (http://urlkick.com/) ------------------------------------------------------------------------ FFMG's Profile: http://www.httppoint.com/member.php?userid=580 View this thread: http://www.httppoint.com/showthread.php?t=17868 Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing). |
| |||
| FFMG wrote: > Captain Paralytic;78563 Wrote: >> >> ... >> INSERT INTO TABLEB ( >> COLA, >> COLB, >> COLC >> ) >> SELECT COLA, COLB, 'COLC' FROM TABLEA > > Thanks, you are right I was talking about COLA/B/C > > I just want to make sure that COLB will not be a problem as I am > inserting an INT into a VARCHAR(255). I don't need to convert > anything? > > FFMG I always find the best way to be sure of these things is to knock up test tables and try it out! |
| |||
| Paul Lautman;78676 Wrote: > FFMG wrote: > > Captain Paralytic;78563 Wrote: > >> > >> ... > >> INSERT INTO TABLEB ( > >> COLA, > >> COLB, > >> COLC > >> ) > >> SELECT COLA, COLB, 'COLC' FROM TABLEA > > > > Thanks, you are right I was talking about COLA/B/C > > > > I just want to make sure that COLB will not be a problem as I am > > inserting an INT into a VARCHAR(255). I don't need to convert > > anything? > > > > FFMG > > I always find the best way to be sure of these things is to knock up > test > tables and try it out! Yes, that's what I did, and it does work. But my question was kind of 'best practice'. Because I am sure that moving a float to a string might cause some problems. (Just guessing here). It might work, but is it the right way? FFMG -- 'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory' (http://www.webhostshunter.com/) | 'Recreation Vehicle insurance' (http://www.insurance-owl.com/other/car_rec.php) 'Free URL redirection service' (http://urlkick.com/) ------------------------------------------------------------------------ FFMG's Profile: http://www.httppoint.com/member.php?userid=580 View this thread: http://www.httppoint.com/showthread.php?t=17868 Message Posted via the webmaster forum http://www.httppoint.com, (Ad revenue sharing). |
| ||||
| On 28 Jun, 06:15, FFMG <FFMG.2sv...@no-mx.httppoint.com> wrote: > Paul Lautman;78676 Wrote: > > > > > > > FFMG wrote: > > > Captain Paralytic;78563 Wrote: > > > >> ... > > >> INSERT INTO TABLEB ( > > >> COLA, > > >> COLB, > > >> COLC > > >> ) > > >> SELECT COLA, COLB, 'COLC' FROM TABLEA > > > > Thanks, you are right I was talking about COLA/B/C > > > > I just want to make sure that COLB will not be a problem as I am > > > inserting an INT into a VARCHAR(255). I don't need to convert > > > anything? > > > > FFMG > > > I always find the best way to be sure of these things is to knock up > > test > > tables and try it out! > > Yes, that's what I did, and it does work. > > But my question was kind of 'best practice'. > > Because I am sure that moving a float to a string might cause some > problems. > (Just guessing here). > > It might work, but is it the right way? > > FFMG > > -- > > 'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory' > (http://www.webhostshunter.com/) | 'Recreation Vehicle insurance' > (http://www.insurance-owl.com/other/car_rec.php) > 'Free URL redirection service' (http://urlkick.com/) > ------------------------------------------------------------------------ > FFMG's Profile:http://www.httppoint.com/member.php?userid=580 > View this thread:http://www.httppoint.com/showthread.php?t=17868 > > Message Posted via the webmaster forumhttp://www.httppoint.com, (Ad revenue sharing).- Hide quoted text - > > - Show quoted text - The "right" way I guess is to use a CAST function and some SQL implementations may require you to do this. MySQL however will handle the casting for you. |