For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > April 2004 > "copy" data









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author "copy" data
Marco Belli

2004-04-13, 3:39 pm

hi
i have a little problem, i'm searching a query that will make me albe to
copy lot's of row in the same table

i have this situation
name year
aa 2000
bb 2000
cc 2000

and want this result

aa 2000
bb 2000
cc 2000
aa 2001
bb 2001
cc 2001

all data shoudl be duplicated and ONLY a column should change

Andy Hassall

2004-04-13, 3:39 pm

On Tue, 13 Apr 2004 18:53:13 GMT, Marco Belli <elcabesa@inwind.it> wrote:

>i have a little problem, i'm searching a query that will make me albe to
>copy lot's of row in the same table
>
>i have this situation
>name year
>aa 2000
>bb 2000
>cc 2000
>
>and want this result
>
>aa 2000
>bb 2000
>cc 2000
>aa 2001
>bb 2001
>cc 2001
>
>all data shoudl be duplicated and ONLY a column should change


INSERT INTO tab
SELECT name, year + 1
FROM tab
WHERE year = 2000

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Marco Belli

2004-04-13, 4:33 pm

Andy Hassall wrote:

> On Tue, 13 Apr 2004 18:53:13 GMT, Marco Belli <elcabesa@inwind.it> wrote:
>
>
> INSERT INTO tab
> SELECT name, year + 1
> FROM tab
> WHERE year = 2000
>


maybe i'm wrong, but i read on mysql manual that you can't write in the tab
you rad from.....
am i worng?
> Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
> http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space


Andy Hassall

2004-04-13, 4:33 pm

On Tue, 13 Apr 2004 19:11:22 GMT, Marco Belli <elcabesa@inwind.it> wrote:

>
>maybe i'm wrong, but i read on mysql manual that you can't write in the tab
>you rad from.....
>am i worng?


No idea, check the manual, or just try it. You never mentioned MySQL so I gave
a generic solution that works on most databases.

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Marco Belli

2004-04-16, 3:34 pm

Andy Hassall wrote:


manual told me that it will not work because source & destination database
are the same, but i tried it and IT WORK =)

> On Tue, 13 Apr 2004 19:11:22 GMT, Marco Belli <elcabesa@inwind.it> wrote:
>
>
> No idea, check the manual, or just try it. You never mentioned MySQL so I
> gave
> a generic solution that works on most databases.
>
> --
> Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
> http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com