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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:46:22+00:00 2026-06-09T15:46:22+00:00

I am not sure if this is possible but here goes. I am using

  • 0

I am not sure if this is possible but here goes.

I am using MySQL and need to complete a statement that produces an output as follows.

I have a table which contains a completeddate field and an enquirydate field.

I need to get data on the time difference between theses fields for which I have the following code

SELECT DATE (completedate) - DATE (enqdate) AS `timediff`, COUNT(*) AS TotalCount
FROM cia_enquiry
WHERE (DATEDIFF(CURDATE(), enqdate) < 30) AND completedate > 1
GROUP BY `timediff`
ORDER BY `timediff` ASC

The above code simply outputs a figure of days between the dates and the total count of entires within the last 30 days (and not counting those entries that are not complete)

I now need to reference the “timediff” results against another table and pull another field from that table.

For example if timediff = 1, then we need to find the id of 1 in another table and return the description field from this table.

Ultimately we should end up with something similar to


timediff     TotalCount         description
0               52                      Within 24 hrs
1               13                      24-48hrs
etc etc ………

  • 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-09T15:46:24+00:00Added an answer on June 9, 2026 at 3:46 pm

    It can be done; you have two choices

    1. Create a temporary table with the result of your query and then join this table with your second table
    2. Use your first query as a subquery and join it with your second table

    Option 1

    create temporary table temp_tbl
    select
       ...
    ;
    # Important: create the indexes you need
    alter table temp_tbl
       add index index1(field1), ... ;
    # Now join your second table
    select a.*, b.*
    from temp_tbl as a join tbl2 as b on ...;
    

    Option 2

    select a.*, b.*
    from (
        select ... # here is your query
        ) as a join tbl2 as b on ...
    

    Hope this helps you

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

Sidebar

Related Questions

Not sure if this is possible, but here goes. I have a MongoDB (using
I'm not sure if this is even possible but here goes: Currently I have
Not sure if this has an answer, but here goes. I'm using JUnit 4.8.1
I'm not sure this is even possible, but here goes: I have a class
I'm not sure if this is even possible, but here goes: I have a
I'm not sure if this is even remotely possible but here it goes: is
Not sure this is possible, but looking to write a script that would return
I'm not sure if this is the right place to ask, but here goes...
I'm not sure exactly how to describe this question, but here goes. I've got
I'm not really sure how I can explain this, but here goes: I want

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.