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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:12:32+00:00 2026-05-24T03:12:32+00:00

im trying to generate a report using CodeIgniter and Datatables.net . Now i’m trying

  • 0

im trying to generate a report using CodeIgniter and Datatables.net .

Now i’m trying to the amount of closed jobs (its a human resources system). I used to query all jobs and in PHP do a foreach and then doing the calcs.

Because im want to use all the features of Datatables (sorting specifically) im trying to do all the calcs in mySQL.

The problem is: the second subquery is very very very slow.

SELECT 
jobs.jobs_id, clients.nome_fantasia, concat_ws(' ', user_profiles.first_name, user_profiles.last_name) as fullname, 
jobs.titulo_vaga, jobs.qtd_vagas, company.name as nome_company, jobs_status.name as      status_name, DATEDIFF(NOW(), jobs.data_abertura) as date_idade, 
(select count(job_cv.jobs_id) from job_cv where job_cv.jobs_id = jobs.jobs_id) as qtd_int,
(select count(distinct job_cv.user_id) from job_cv_history join job_cv on job_cv.job_cv_id = job_cv_history.job_cv_id where job_cv_history.status = '11' and job_cv.jobs_id = jobs.jobs_id ) as fechadas 
FROM (jobs)
JOIN clients ON lients.clients_id=jobs.clients_idJOIN user_profiles ON jobs.consultor_id=user_profiles.user_id
JOIN jobs_status ON jobs.status=jobs_status.jobs_status_id 
JOIN company ON jobs.company_id=company.company_id 
LIMIT 50

Some one can help me? I can provide more information if its needed.

UPDATE

The idea to use JOIN instead SELECT work with the first subquery but with the second one not, there a way to pass a ‘variable’ to use inside the subquery? Like the current jobs_id?

UPDATE AGAIN

This line works fine by itself. But inside the subquery take about a minute with worng values

SELECT job_cv.jobs_id,count(distinct job_cv.user_id) AS fechadas
FROM job_cv_history 
JOIN job_cv 
ON job_cv.job_cv_id = job_cv_history.job_cv_id 
WHERE job_cv_history.status = '11'
GROUP BY job_cv.jobs_id
  • 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-24T03:12:34+00:00Added an answer on May 24, 2026 at 3:12 am

    It is not subquery that is slow. It’s the fact, that you’re executing these subqueries for each row returned from outer query. Move these to joins instead, and you should observe increase in performance.

    SELECT 
      jobs.jobs_id, clients.nome_fantasia, concat_ws(' ', user_profiles.first_name, user_profiles.last_name) as fullname, 
    jobs.titulo_vaga, jobs.qtd_vagas, company.name as nome_company, jobs_status.name as      status_name, DATEDIFF(NOW(), jobs.data_abertura) as date_idade, 
    qtd.qtd_int,
    fechadas.fechadas 
    FROM (jobs)
    JOIN clients ON lients.clients_id=jobs.clients_idJOIN user_profiles ON jobs.consultor_id=user_profiles.user_id
    JOIN jobs_status ON jobs.status=jobs_status.jobs_status_id 
    JOIN company ON jobs.company_id=company.company_id 
    JOIN (
      SELECT jobs_id, count(jobs_id) AS qtd_int FROM job_cv GROUP BY jobs_id
    ) AS qtd ON qtd.jobs_id = jobs.jobs_id
    JOIN (
      SELECT job_cv.user_id, count(distinct job_cv.user_id) AS fechadas
      FROM job_cv_history 
      JOIN job_cv 
      ON job_cv.job_cv_id = job_cv_history.job_cv_id 
      WHERE job_cv_history.status = '11'
      GROUP BY job_cv.user_id
    ) AS fechadas ON job_cv.jobs_id = jobs.jobs_id
    LIMIT 50
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to generate a grouped/stratified report using PHP and MySQL. tbl_items has
I am trying to generate a report using Oracle but am having some alignment
I'm using netBeans and I'm trying to generate a report unsing Jasper Report Can
I am trying to generate my ADO.NET entity model from my MySQL database using
I'm trying to generate code coverage reports with EMMA using tests of which some
I am trying to generate a report by querying 2 databases (Sybase) in classic
I'm working on trying to generate a report from a couple of database tables.
I am trying to write a view that will generate a report which displays
I'm trying to generate a sitemap.xml on the fly for a particular asp.net website.
I am trying to generate equivalent MD5 hashes in both JavaScript and .Net. Not

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.