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

  • Home
  • SEARCH
  • 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 8429945
In Process

The Archive Base Latest Questions

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

I have two tables, sprockets and cogs . create table sprockets( id NUMBER );

  • 0

I have two tables, sprockets and cogs.

create table sprockets(
    id NUMBER
);

INSERT into sprockets VALUES (4);
INSERT into sprockets VALUES (8);
INSERT into sprockets VALUES (15);
INSERT into sprockets VALUES (16);
INSERT into sprockets VALUES (23);
INSERT into sprockets VALUES (42);

create table cogs(
    id NUMBER
);

I want to take some ids from sprockets and put them into cogs.

insert into cogs select id from sprockets s where s.id < 40 and MOD(s.id, 3) != 0;

This adds sprockets 4, 8, 16, 23 to cogs as expected.

4 rows inserted

As my sprocket making business grows, the business logic for determining which sprockets require cogs will become much more complicated. So I would like to use a sequence of temporary tables that filter out non-candidate sprockets. I believe this is more maintainable than a one line statement with no comments.

--sprockets with ids greater than 40 are too big to frob, 
--so it's impossible to weld a cog to them
with frobbableSprockets as(
    select id from sprockets where sprockets.id < 40
),

--non-greppable sprockets have built-in harmonic oscillators, 
--so cogs are not required
greppableFrobbableSprockets as(
    select id from frobbableSprockets f where MOD(f.id,3) != 0
),

--not pictured: more filtering using arcane business logic, 
--including but not limited to:
--whether it is raining on a tuesday,
--and if the moon is in the seventh house.

--sprockets with ids less than 3 are from the legacy system and already have cogs
sprocketsRequiringCogs as(
    select id from greppableFrobbableSprockets f where f.id > 3
)

insert into cogs select id from sprocketsRequiringCogs

This code is relatively readable, but unfortunately it does not work!

insert into cogs select id from sprocketsRequiringCogs 
Error at Command Line:18 Column:2
Error report:
SQL Error: ORA-00928: missing SELECT keyword

If I change the last line to select id from sprocketsRequiringCogs, there is no error, so I know the problem must be in the insert statement and not in the declaration of the temporary tables.

The one-line insert statement works, and the multi-line insert statement does not work. The only difference I see is that the latter is getting its values from a temporary table.

Why can’t I insert rows from a temporary table?

  • 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-10T05:28:32+00:00Added an answer on June 10, 2026 at 5:28 am

    This is a guess, I have no possibility to try it out right now, but possibly this could work:

    insert into cogs
    with frobbableSprockets as(
        select * from sprockets where sprockets.id < 40
    ),
    ...
    select * from sprocketsRequiringCogs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that I want to join into one table and use
I have two tables CREATE TABLE table1 (id int primary key auto_increment,....); CREATE TABLE
I have two tables, orders and old_orders. Each table has some similar fields and
I have two tables in my MySQL database (table1 and table 2). I want
I have two tables, I want to transfer all data from the first table
I have two tables with the following definitions: CREATE TABLE [dbo].[Shows] ( [Id] UNIQUEIDENTIFIER
I have two tables: CREATE TABLE tblEatables ( `EatId` int UNSIGNED PRIMARY AUTO_INCREMENT, `Fruits`
I have two tables, a message table and a log table. I want to
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables one with ID and NAME table 1 ID | NAME

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.