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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:09:29+00:00 2026-05-11T21:09:29+00:00

Hey guys. This is a follow-on from this question : After getting the right

  • 0

Hey guys. This is a follow-on from this question:

After getting the right data and making some tweaks based on requests from business, I’ve now got this mini-beast on my hands. This query should return the total number of new jobseeker registrations and the number of new uploaded CV’s:

SELECT COUNT(j.jobseeker_id) as new_registrations,
(
    SELECT 
      COUNT(c.cv_id)
    FROM 
      tb_cv as c, tb_jobseeker, tb_industry
    WHERE
      UNIX_TIMESTAMP(c.created_at) >= '1241125200'
    AND 
      UNIX_TIMESTAMP(c.created_at) <= '1243717200'
    AND 
      tb_jobseeker.industry_id = tb_industry.industry_id
) 
AS uploaded_cvs
FROM 
  tb_jobseeker as j, tb_industry as i
WHERE
  j.created_at BETWEEN '2009-05-01' AND '2009-05-31'
AND
  i.industry_id = j.industry_id
GROUP BY i.description, MONTH(j.created_at) 

Notes:
– The two values in the UNIX TIMESTAMP functions are passed in as parameters from the report module in our backend.

Every time I run it, MySQL chokes and lingers silently into the ether of the Interweb.

Help is appreciated.

Update: Hey guys. Thanks a lot for all the thoughtful and helpful comments. I’m only 2 weeks into my role here, so I’m still learning the schema. So, this query is somewhere between a thumbsuck and an educated guess. Will start to answer all your questions now.

  • 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-05-11T21:09:29+00:00Added an answer on May 11, 2026 at 9:09 pm

    tb_cv is not connected to the other tables in the sub-query. I guess this is the root cause for the slow query. It causes generation of a Cartesian product, yielding a lot more rows than you probably need.

    Other than that I’d say you need indexes on tb_jobseeker.created_at, tb_cv.created_at and tb_industry.industry_id, and you might want to get rid of the UNIX_TIMESTAMP() calls in the sub-query since they prevent use of an index. Use BETWEEN and the actual field values instead.

    Here is my attempt at understanding your query and writing a better version. I guess you want to get the count of new jobseeker registrations and new uploaded CVs per month per industry:

    SELECT 
      i.industry_id,
      i.description, 
      MONTH(j.created_at)            AS month_created,
      YEAR(j.created_at)             AS year_created,
      COUNT(DISTINCT j.jobseeker_id) AS new_registrations,
      COUNT(cv.cv_id)                AS uploaded_cvs
    FROM 
      tb_cv AS cv
      INNER JOIN tb_jobseeker AS j ON j.jobseeker_id = cv.jobseeker_id
      INNER JOIN tb_industry  AS i ON i.industry_id  = j.industry_id
    WHERE
      j.created_at BETWEEN '2009-05-01' AND '2009-05-31'
      AND cv.created_at BETWEEN '2009-05-01' AND '2009-05-31'
    GROUP BY 
      i.industry_id,
      i.description, 
      MONTH(j.created_at),
      YEAR(j.created_at)
    

    A few things I noticed while writing the query:

    • you GROUP BY values you don’t output in the end. Why? (I’ve added the grouped field to the output list.)
    • you JOIN three tables in the sub-query while only ever using values from one of them. Why? I don’t see what it would be good for, other than filtering out CV records that don’t have a jobseeker or an industry attached — which I find hard to imagine. (I’ve removed the entire sub-query and used a simple COUNT instead.)
    • Your sub-query returns the same value every time. Did you maybe mean to correlate it in some way, to the industry maybe?.
    • The sub-query runs once for every record in a grouped query without being wrapped in an aggregate function.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys. This is a very simple question, I'm sure, but I'm getting myself
Hey guys this question is a bit nebulous so I apologize...I'm just looking for
Hey guys, this question might be a little weird worded but I was looking
hey guys, i'm getting an exception on the following inner exception: {Value cannot be
Hey right now I'm using jQuery and I have some global variables to hold
Hey guys! First of all, I know this kind of stuff is quite shitty,
hey guys m having this wierd exception of cast though my datatypes are correct
Hey guys - I'm stuck with this problem and im just wondering what the
hey guys when I store this string: http://61.147.96.19/f4v/41/53283141.h264_2.f4v?10000&key=d7d7488b5dd4a35aac3e784cf4acb1a174ddc7&amp;playtype=1&amp;tk=2038443745&amp;brt=3&amp;id=tudou&amp;itemid=30165756&amp;fi=53283141&amp;sz=19354294 in a variable @longurl and use
Hey guys, I got this error message when I tried to trigger the function

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.