Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8713953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:28:24+00:00 2026-06-13T05:28:24+00:00

I have a row of data in a table: Key | Val1 | Val2

  • 0

I have a row of data in a table:

Key | Val1 | Val2
----+------+-----
1   | A    | B

I would like to copy this row, but assign each new row a different key (actually a foreign key) from a list:

New keys
--------
2
3
4

This list can easily be obtained via a query. After the duplication, the table should look like this:

Key | Val1 | Val2
----+------+-----
1   | A    | B
2   | A    | B
3   | A    | B
4   | A    | B

So far, all I’ve come up with is this:

INSERT INTO table (Key, Val1, Val2) (
    SELECT '2' AS Key, Val1, Val2 FROM table WHERE Key='1'
);

This works, but of course it only copies one row at a time. Is there a way to copy all the rows at once?

I’m using Oracle if it makes a difference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:28:25+00:00Added an answer on June 13, 2026 at 5:28 am

    You can use SELECT .. FROM DUAL to make up values, and you can use UNION ALL to combine multiple rows into a single result. There are various other ways to create a result set such as a Recursive Common Table Expression.

    INSERT INTO table (Key, Val1, Val2)
    SELECT d.newKey, t.Val1, t.Val2
    FROM table t
    cross join (select 2 NewKey from dual union all
                select 3 NewKey from dual union all
                select 4 NewKey from dual) d;
    

    If your new keys come from a subquery, it’d be even easier, e.g.

    INSERT INTO table (Key, Val1, Val2)
    SELECT d.FKey, t.Val1, t.Val2
    FROM table t
    cross join (select FKey
                from SomeOtherTable
                Where ......) d;
    

    However, do note that because you’re copying FROM table and INTO table, you’ll replicate ALL the records from table at the same time for each foreign key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data table filled with text in each table row. How do
Ok, I have a table which contains multiple rows. Each row contains some data
I currently have the following row in my table: course_data: user_id days <-- This
I have two tables, structured like so: table A: A_ID varchar(32) PRIMARY KEY field1
I have a single row of data in a SQL Server table that I'm
I have this test table with one row entry and 2 indexes, the first
I have this table: create table demo ( key number(10) not null, type varchar2(3)
I have two data tables which have a primary key column in common but
I have a list of objects that contain row data for a table. There
I have a table Datawarehouse which the population went wrong. Each row has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.