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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:49:27+00:00 2026-06-15T08:49:27+00:00

I have a quick question… I want to combine two sql queries into one

  • 0

I have a quick question…

I want to combine two sql queries into one but the problem is that both these queries have GROUP BY in it.

Query 1:

SELECT   COUNT(users_survey_answers.ultimate_survey_code)
FROM     company,
         users_codes,
         users_survey_answers
WHERE    company.company_id = users_codes.company_id
  AND    users_codes.email = "test@gmail.com"
  AND    users_codes.company_id = users_survey_answers.company_id
  AND    users_survey_answers.completed = 0
GROUP BY users_codes.company_id

Query 2:

SELECT   COUNT(users_rewards.reward_id)
FROM     company, 
         users_codes, 
         users_rewards
WHERE    company.company_id = users_codes.company_id
  AND    users_codes.email = "test@gmail.com"
  AND    users_rewards.company_id = users_codes.company_id
  AND    redeemed = 0
GROUP BY users_codes.company_id

I appreciate the help. I have tried so many solutions, still no help.

Thanks.

  • 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-15T08:49:29+00:00Added an answer on June 15, 2026 at 8:49 am

    Try this:

    SELECT    company.company_id,
              users_pts.pts as CompanyPts,
              t1.ultimate_survey_code_count,
              t2.reward_id_count
    FROM      company,
              users_codes
    INNER JOIN (
              SELECT 
                  company_id, 
                  COUNT(ultimate_survey_code) AS ultimate_survey_code_count
              FROM users_survey_answers
              WHERE completed = 0
              GROUP BY company_id
              ) AS t1
           ON users_codes.company_id = t1.company_id
    INNER JOIN (
              SELECT 
                  company_id, 
                  SUM(IF(redeemed = 0, 1, 0)) AS reward_redeem_zero_count,
                  SUM(IF(redeemed = 0, 0, 1)) AS reward_redeem_not_zero_count
              FROM users_rewards
              GROUP BY company_id
              ) AS t2
           ON users_codes.company_id = t2.company_id
    INNER JOIN users_pts
           ON users_codes.company_id = users_pts.company_id
    WHERE     company.company_id = users_codes.company_id
      AND     users_codes.email = "test@gmail.com"
    

    This is untested, but hope meets your need.

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

Sidebar

Related Questions

I have quick question for you SQL gurus. I have existing tables without primary
I have a quick question that I can't seem to find online. I am
I have a quick question that I just can't seem to figure out even
I have a quick question - is there a best practice in SQL Table
I have a quick question that I need some help with if possible. Am
I have a quick question about a preg_replace problem I have. I am just
Hello i have a quick question. I get 2 flash messages, the devise one
I have quick question, and it may sound dumb. But for the love of
I just noticed that live() is already deprecated in jQuery. I have quick question
I have a quick question that hopefully someone has worked through before. In the

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.