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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:46:33+00:00 2026-06-11T02:46:33+00:00

I am trying to select data from two tables. The DBA has the tables

  • 0

I am trying to select data from two tables. The DBA has the tables configured in such a way that the first table spools records for 5 minutes, and then a procedure moves the data to the second table and cleans the spool. This repeats constantly. The issue is I need to select data from both tables.

Here is my query so far:

select * from table1,table2 
where ( (table1.field>=DATE_SUB(UTC_TIMESTAMP(), INTERVAL 5 MINUTE))  
OR 
(table2.field>=DATE_SUB(UTC_TIMESTAMP(), INTERVAL 5 MINUTE)) )

Searching for either of the conditions individually works quickly, however when I put them together like above, the system just sits there and becomes unresponsive. I’m just curious what I’m doing wrong. Should I do this with a union instead?

  • 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-11T02:46:35+00:00Added an answer on June 11, 2026 at 2:46 am

    You are joining 2 tables without any joining where clause, so you are pulling in M*N records (a Cartesian product).

    In other words, if table1 has 100 records matching the first condition, and table2 has 10,000 records, you are retrieving 1,000,000 records instead of 10,100. To top that off, every record you are retrieving is 2x the size since it includes all the fields from the row of table1 + all the fields from the row of table2, so not only are you increasing the amount of rows by 100x (using my example #s), you are also increasing the retrieved data size by 200x.

    What you want is to use a UNION instead of a join.

    select * from table1
    where table1.field>=DATE_SUB(UTC_TIMESTAMP(), INTERVAL 5 MINUTE))  
    UNION
    select * from table2
    where table2.field>=DATE_SUB(UTC_TIMESTAMP(), INTERVAL 5 MINUTE))  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to preform a SELECT query that grabs data from two tables only
I am trying to select data from two tables and insert it into another
I'm trying to get data from two tables. Here is my code: select p.nim,
I'm currently trying to copy data from table into another by using a SELECT
I'm trying to combine data from two tables in MySQL with PHP. I want
I am trying to compare two tables to find rows in each table that
Basically I'm trying to combine two tables together into a new table. The first
I'm trying to make a query where I get data from two tables but
I am trying to import data from a large database. I have two tables
I'm using two tables for my current project(it will grow certainly). First table has

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.