vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   SQL query question - Copy a column from one table to another (https://vborg.vbsupport.ru/showthread.php?t=75780)

cinq 02-05-2005 12:16 PM

SQL query question - Copy a column from one table to another
 
How can this be done ?

Background:
One table, articles_article has already been created, with rows having the first column articles_articleid, being the unique id for each row.

I want to create another table, articles_newtable with exactly the same number of rows with each row having the same corresponding articles_articleid.

How can this be achieved ?
Thanks in advance :)

Xenon 02-05-2005 12:23 PM

that way should work:

[sql]
INSERT INTO articles_newtable (articleid)
SELECT articles_articleid FROM articles_article[/sql]

so you see you can mix up insert an select queries :)

cinq 02-05-2005 12:25 PM

I never knew that ! Thanks Stefan :D

Xenon 02-05-2005 12:29 PM

you're welcome

Michael Morris 02-05-2005 03:22 PM

A similar technique can be used to copy table contents over within or even between databases.

[sql]create table destinationdatabase.newtable
select * from sourcedatabase.oldtable[/sql]

You don't have to specificy databases if making a transfer within the same database.

Xenon 02-06-2005 07:40 PM

hey, that one was even new to me :)

you see you can learn more every day..

Dean C 02-06-2005 07:45 PM

This is an enlightening thread :)


All times are GMT. The time now is 12:45 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01027 seconds
  • Memory Usage 1,709KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete