Unix Technical Forum

Moving data from one table to another, (existing), one.

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 10:07 AM
FFMG
 
Posts: n/a
Default Moving data from one table to another, (existing), one.


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).

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 10:07 AM
Captain Paralytic
 
Posts: n/a
Default Re: Moving data from one table to another, (existing), one.

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 10:08 AM
FFMG
 
Posts: n/a
Default Re: Moving data from one table to another, (existing), one.


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).

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 10:08 AM
Paul Lautman
 
Posts: n/a
Default Re: Moving data from one table to another, (existing), one.

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!


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 10:08 AM
FFMG
 
Posts: n/a
Default Re: Moving data from one table to another, (existing), one.


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).

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 10:08 AM
Captain Paralytic
 
Posts: n/a
Default Re: Moving data from one table to another, (existing), one.

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:57 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com