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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:40:42+00:00 2026-05-22T00:40:42+00:00

Not sure if this is possible, but if it is it would make my

  • 0

Not sure if this is possible, but if it is it would make my query much faster.

Basically I have a query like this:

 SELECT *
   FROM (SELECT bar.id
           FROM pivot_table
          WHERE foo.id = x) t1
   JOIN (SELECT count(*) c1, bar.id
           FROM table
       GROUP BY bar.id) t2 ON t1.id = t2.id
   JOIN (SELECT count(*) c2, bar.id
           FROM another_table
       GROUP BY bar.id) t3 ON t1.id = t3.id

But this is quite slow because table and another_table are huge. But really I am only interested in those values resulting from the query in t1. So if I could somehow get those results into an IN clause for t2 and t3 the query ought to speed up significantly.

Is this possible?


Not too clear I guess. OK what I was thinking is that changing the query to something like:

 SELECT *
   FROM (GROUP_CONCAT (bar.id) as results
                 FROM pivot_table
                WHERE foo.id = x) t1
         JOIN (SELECT count(*) c1, bar.id
                 FROM table
                WHERE bar.id IN (*results from t1*)
                GROUP BY bar.id) t2 ON t1.id = t2.id
         JOIN (SELECT count(*) c2, bar.id
                 FROM another_table
                WHERE bar.id IN (*results from t1*)
                GROUP BY bar.id) t3 ON t1.id = t3.id

Might be quicker because it narrows down the number of rows scanned in t2 and t3. Would that not be the case?


Everyone wants to see it, so here is the full query:

SELECT   (k_group.count/jk_group.count) * (s_group.count/jk_group.count) AS ratio,
         jk_group.k_id                                                           ,
         jk_group.s_id
FROM
         -- find the keywords for the job
         (SELECT jk.keyowrd_id AS k_id
         FROM    jobs_keywords jk
         WHERE   job_id = 50100
         )
         extracted_keywords
         -- calculate the necessary values using group_by functions
         INNER JOIN
                  (SELECT  COUNT(*)   count,
                           skill_id   AS s_id ,
                           keyword_id AS k_id
                  FROM     jobs_keywords jk
                           JOIN jobs_skills js
                           ON       js.job_id = jk.job_id
                           JOIN job_feed_details d
                           ON       d.job_id = js.job_id
                  WHERE    d.moderated       = 1
                  GROUP BY skill_id,
                           keyword_id
                  )
                  jk_group
         ON       extracted_keywords.k_id = jk_group.k_id
         INNER JOIN
                  (SELECT  COUNT(*)      count,
                           keyword_id AS k_id
                  FROM     jobs_keywords jk
                           JOIN job_feed_details d
                           ON       d.job_id = js.job_id
                  WHERE    d.moderated       = 1
                  GROUP BY keyword_id
                  )
                  k_group
         ON       jk_group.k_id = k_group.k_id
         INNER JOIN
                  (SELECT  COUNT(*)    count,
                           skill_id AS s_id
                  FROM     jobs_skills js
                           JOIN job_feed_details d
                           ON       d.job_id = js.job_id
                  WHERE    d.moderated       = 1
                  GROUP BY skill_id
                  )
                  s_group
         ON       jk_group.s_id = s_group.s_id
ORDER BY ratio DESC
LIMIT    25
  • 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-22T00:40:42+00:00Added an answer on May 22, 2026 at 12:40 am

    I was able to accomplish what I was trying to do like so:

     SELECT *
       FROM (@var:=GROUP_CONCAT(bar.id) as results
                     FROM pivot_table
                    WHERE foo.id = x) t1
             JOIN (SELECT count(*) c1, bar.id
                     FROM table
                    WHERE bar.id IN (@var)
                    GROUP BY bar.id) t2 ON t1.id = t2.id
             JOIN (SELECT count(*) c2, bar.id
                     FROM another_table
                    WHERE bar.id IN (@var)
                    GROUP BY bar.id) t3 ON t1.id = t3.id
    

    But the benefits in terms of speed were not too significant. I have now abandoned the one query approach in favor of many smaller queries, and that is much better.

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

Sidebar

Related Questions

I'm not sure if this is possible, but I would like to create a
Not sure this is possible, but looking to write a script that would return
I'm not sure if this is possible but I'd like to be able to
I'm not sure if this is possible (complete non-flash developer speaking), but we have
I'm not sure if this is possible in LINQ, but I have the following
I'm not sure if this is even possible but here goes: Currently I have
I'm not sure if this is possible, but I thought it would be cool
I'm not sure if this is possible but I want to see objects created
I'm not sure if this is possible but as I was looking for a
I'm not sure this is possible, but in ruby, you can dynamically call a

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.