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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:55:58+00:00 2026-06-07T16:55:58+00:00

How would I combine these two queries into 1 and to run efficiently on

  • 0

How would I combine these two queries into 1 and to run efficiently on a large table?

SELECT  field1, count(1) as requestCount
FROM table1
WHERE date_complete >= '2012-06-12 00:00:00' 
      AND date_complete <= '2012-07-12 23:59:59' 
GROUP BY field1

SELECT field2, count(1) as completeCount
FROM table1
WHERE date_complete >= '2012-06-12 00:00:00' 
      AND date_complete <= '2012-07-12 23:59:59' 
GROUP BY field2

Table holds information for a process where multiple users are involved. For example say the first person creates the request, second person completes the request and the third closes out the request by filing it.

I want to count how many each user requested, completed and filed in a specific time frame

I want these two combined to look like

+----------------+--------------+
| field1         | requestCount |
+----------------+--------------+
| PJB            |            1 |
| RFD            |            6 |
| YAS            |            4 |
+----------------+--------------+

+

+---------+---------------+
| field2  | completeCount |
+---------+---------------+
| PJB     |            4  |
| YAS     |            5  |
+---------+---------------+

=

+----------------+--------------+---------------+
| Username       | requestCount | completeCount |
+----------------+--------------+---------------+
| PJB            |            1 |             4 |
| RFD            |            6 |             0 |
| YAS            |            4 |             5 |
+----------------+--------------+---------------+
  • 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-07T16:56:00+00:00Added an answer on June 7, 2026 at 4:56 pm
    select  o.USERNAME, a.requestCount , b.completeCount from (SELECT  USERNAME
    FROM owner_login_pass )
     as o left join (SELECT field1, count(1) as requestCount
    FROM table1
    WHERE date_complete between '2012-06-12 00:00:00' and '2012-07-12 23:59:59' 
    GROUP BY field1) as a on o.USERNAME=a.field1
    left join (SELECT field2, count(1) as completeCount
    FROM table1
    WHERE date_complete between '2012-06-12 00:00:00' and '2012-07-12 23:59:59' 
    GROUP BY field2) as b on o.USERNAME=b.field2
    

    You would need to ensure that field1 has all of the users that you would need to display data for. Otherwise, you would need to join to a users table as well.

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

Sidebar

Related Questions

I would like to combine these four queries into one: SELECT COUNT(ID) FROM conversations
I'm trying to combine these two select queries but the count function is confusing
I have these 2 queries that I would like to combine into one big
I have two queries $query1=SELECT staffid, COUNT(staffid) FROM enrll GROUP BY staffid ORDER BY
How would I combine (stack vertically) the following 3 queries into one query that
I would like to combine the DisplayNames from two different ViewModels, but only IF
I have two views that I would like to combine into one. The first
I have two queries which i would like to combine There are 4 tables
How would I combine the following two queries to produce a combination of the
How would I combine the two columns if there is a Null in one

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.