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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:34:29+00:00 2026-06-13T13:34:29+00:00

I need a query that quickly shows the articles within a particular module (a

  • 0

I need a query that quickly shows the articles within a particular module (a subset of articles) that a user has NOT uploaded a PDF for. The query I am using below takes about 37 seconds, given there are 300,000 articles in the Article table, and 6,000 articles in the Module.

SELECT * 
FROM article a 
INNER JOIN article_module_map amm ON amm.article=a.id 
WHERE amm.module = 2 AND
    a.id NOT IN ( 
        SELECT afm.article 
        FROM article_file_map afm 
        INNER JOIN article_module_map amm ON amm.article = afm.article 
        WHERE afm.organization = 4 AND 
            amm.module = 2 
    ) 

What I am doing in the above query is first truncating the list of articles to the selected module, and then further truncating that list to the articles that are not in the subquery. The subquery is generating a list of the articles that an organization has already uploaded PDF’s for. Hence, the end result is a list of articles that an organization has not yet uploaded PDF’s for.

Help would be hugely appreciated, thanks in advance!

EDIT 2012/10/25

With @fthiella’s help, the below query ran in an astonishing 1.02 seconds, down from 37+ seconds!

SELECT a.* FROM (
    SELECT article.* FROM article 
    INNER JOIN article_module_map
        ON article.id = article_module_map.article
    WHERE article_module_map.module = 2
) AS a
LEFT JOIN article_file_map
    ON a.id = article_file_map.article
    AND article_file_map.organization=4
WHERE article_file_map.id IS NULL
  • 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-13T13:34:29+00:00Added an answer on June 13, 2026 at 1:34 pm

    I am not sure that i can understand the logic and the structure of the tables correctly. This is my query:

    SELECT
      article.id
    FROM
      article
        INNER JOIN
      article_module_map
        ON article.id = article_module_map.article
        AND article_module_map.module=2
      LEFT JOIN
        article_file_map
        ON article.id = article_file_map.article
        AND article_file_map.organization=4
    WHERE
      article_file_map.id IS NULL
    

    I extract all of the articles that have a module 2. I then select those that organization 4 didn’t provide a file.

    I used a LEFT JOIN instead of a subquery. In some circumstances this could be faster.

    EDIT Thank you for your comment. I wasn’t sure it would run faster, but it surprises me that it is so much slower! Anyway, it was worth a try!

    Now, out of curiosity, I would like to try all the combinations of LEFT/INNER JOIN and subquery, to see which one runs faster, eg:

    SELECT *
    FROM
      (SELECT *
       FROM
         article INNER JOIN article_module_map
         ON article.id = article_module_map.article
       WHERE
         article_module_map.module=2)
      LEFT JOIN
    etc.
    

    maybe removing *, and I would like to see what changes between the condition on the WHERE clause and on the ON clause… anyway I think it doesn’t help much, you should concentrate on indexes now.

    Indexes on keys/foreign key should be okay already, but what if you add an index on article_module_map.module and/or article_file_map.organization ?

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

Sidebar

Related Questions

I need a SQL Query that shows me all polls a user (uid) has
Database has tables Photos and PhotoAlbums. I need a query that will select all
I have a query that I need to execute that I do not know
I need a query that will return a table where each column is the
I need a SQLite query that searches 1 field only using LIKE. Basic example:
Need help with a query that I wrote: I have three tables Company id
I need to write a query that returns all object less that or equal
I need to write a query that will go through a table, find duplicate
I need to run a query that returns a list of users, along with
I need to setup a SELECT query that will return rows based on matching

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.