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 686831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:03:52+00:00 2026-05-14T02:03:52+00:00

How would I store the result of a select statement so I can reuse

  • 0

How would I store the result of a select statement so I can reuse the results with an in clause for other queries? Here’s some pseudo code:

declare
  ids <type?>;
begin
  ids := select id from table_with_ids;
  select * from table1 where id in (ids);
  select * from table2 where id in (ids);
end;

… or will the optimizer do this for me if I simply put the sub-query in both select statements?

EDIT: Here’s more information about the structure of my tables.

Basically table1 is a standard table with the id being the primary key. While table2 has a 3-column primary key with id being one of those columns. In my case the id in table2 will appear in three rows.

  • 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-05-14T02:03:52+00:00Added an answer on May 14, 2026 at 2:03 am

    You could use a SQL table object to store the result of the select and reuse it. It will consume more memory and will probably be efficient only if the first SELECT takes a lot of time.

    CREATE TYPE tab_number IS TABLE OF NUMBER;
    /
    

    You would use it with a BULK COLLECT INTO clause:

    DECLARE
       ids tab_number;
    BEGIN
       SELECT id BULK COLLECT INTO ids FROM table_with_ids;
       SELECT * /*into ??*/ 
         FROM table1 
        WHERE id IN (SELECT column_value FROM TABLE(ids));
       SELECT * /*into ??*/ 
         FROM table2
        WHERE id IN (SELECT column_value FROM TABLE(ids));
    END;
    

    In version 9i and before you would need to use CAST to query the table:

    SELECT * 
      FROM table2 
     WHERE id IN (SELECT column_value FROM CAST (TABLE(ids) AS tab_number));
    

    Alternatively, you could use a GLOBAL TEMPORARY TABLE to store the intermediate result set.

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

Sidebar

Related Questions

We would like to some processing in a Java application, store the results in
I would like to output the results of a SELECT statement as a JSON
How would I store results from dataset in an Ilist? Model read = new
The following code is a simple select statement that should use the array_sum function
I have a stored procedure which executes a select statement. I would like my
I would like to have a stored procedure that return 3 results. these results
How would you store a vector of N dimensions in a datatable in C#?
How would you store a PDF document in a field in MySQL? Currently I
I have a certificate .p12 and .crt and I would like store the public
I would like to store large dataset generated in Python in a Django model.

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.