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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:38:46+00:00 2026-06-06T09:38:46+00:00

I have just learnt about temporary tables and using them has given me some

  • 0

I have just learnt about temporary tables and using them has given me some really nice speed increases in some of my big queries.

The problem I have is that when I create the table, it doesn’t last for the full length of the following query that uses it nor until the end of the script.

I am creating it using:

$dbh->exec("CREATE TEMPORARY TABLE _temp_unique_invoice_ref ENGINE = MEMORY AS
        (SELECT jobRef, invoiceRef FROM invoices_out_reference GROUP BY invoiceRef)") ;

The query after it is a few hundred lines long and tries to make use of the temporary table many times in subqueries, but it only works for the first subquery and the rest of the query fails saying that the table does not exist.

The scenario is also further complicated by the fact that this query will be run every 10 seconds potentially by many users, so it could be executed many times before 10 seconds has elapsed.

How can I make this work without not using the TEMPORARY keyword and drop etc?


The query that follows is just one large query. Prepare is called on the same object so could that be causing a new connection? Would it work if I put the create table syntax at the start of the larger query and terminate it with ;?

  • 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-06T09:38:54+00:00Added an answer on June 6, 2026 at 9:38 am

    You can use ::

    Insert into temp_table select from table
    

    It will automatically create a table with the description same as table, and when you are done drop it.

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

Sidebar

Related Questions

Have spend quite some time to learn Sencha touch, just like an evaluation about
I have just learnt about Django apps. I want to know that within one
I just learnt the basics of MySQL and I'm wondering about this: I have
im just starting to learn about sockets and i have been given this code,
I am new to Java Persistence API . I have just learnt it and
First the disclaimer: I never learnt any programming in school, and just have to
I'm just starting to learn Xcode, and have run in to some problems... I've
I have just started to learn about the pros of foreign keys in database
For years I've been reading about XML and I have just not quite grokked
I've just started to learn about tie . I have a class named Link

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.