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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:43:58+00:00 2026-06-11T18:43:58+00:00

I have a script of the following structure: SELECT SUM(CASE WHEN pf.info IS NOT

  • 0

I have a script of the following structure:

SELECT SUM(CASE WHEN pf.info IS NOT NULL THEN 1 ELSE 0 END)
FROM summary s 
LEFT JOIN (SELECT id, info FROM items GROUP BY id) pf ON s.id=pf.id
GROUP BY s.date

What I want is to count those id’s which are in ‘summary’ and present in ‘items’. ‘items’ have same id’s repeated several times, that’s why I do GROUP BY.

This script works as I want, but it is extremely slow, much slower than just doing straightforward LEFT JOIN (and counting each id several times). This doesn’t seem to make sense since I need a smaller subspace of that and it should be easier.

So the question is: how to restructure the query to make it quicker?

  • 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-11T18:43:59+00:00Added an answer on June 11, 2026 at 6:43 pm

    Use count(distinct ...):

    SELECT count(distinct s.id)
    FROM summary s 
    JOIN items i ON s.id = i.id
    

    I don’t understand why you are grouping by s.date – there’s no clue in your question as to why, so if it’s not a mistake and you need to group by date, use this:

    SELECT s.date, count(distinct s.id)
    FROM summary s 
    JOIN items i ON s.id = i.id
    GROUP BY s.date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script select c.id from .TBL_COUPONS. as c inner join .TBL_BUSINESS.
I have the following directory structure : /script/x.js /includes/x.txt /1/2/index.html After hooking a webpage
I have the following HTML structure: $('#subgroup a').nextUntil('h3').wrapAll('<div></div>'); <script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js></script> <div id=subgroup> <h3>Group name
I have the following script (adapted from here) for uploading files via ftp for
I have written following script in python which works fine: from sys import argv
I have recently switched from python 2.7 to python 3.2 considering following folder structure:
I have a following question. We are currently trying to select an appropriate structure
I have script which has the following structure: <?php if( a == b ){
I have the following DOM structure : <html> <head> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js type=text/javascript></script> </head> <body>
I have written the following script below - I am not quite happy with

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.