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

The Archive Base Latest Questions

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

This is relating to my last question mysql query with AND, OR and NOT

  • 0

This is relating to my last question mysql query with AND, OR and NOT

Instead of editing the question, I am asking a new one because the question is only part of the previous question with an alteration.

I am looking to do a mysql query that returns me all articles that have all required topics.

Article
   id
   ....

Topic
   id
   ....

ArticleTopics
   article_id
   topic_id
   type

something that would effectively do:

SELECT * FROM Article LEFT JOIN ArticleTopics ON Article.id = ArticleTopics.article_id
WHERE ArticleTopics.topic_id HAS ALL (these topics)

Is this possible? What is the best approach for this?

  • 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-18T06:32:25+00:00Added an answer on May 18, 2026 at 6:32 am

    Several of the other answers suggest using aliases on the child table for each filter clause – this may not be very efficient or scale well.

    Consider:

    SELECT x.*
    FROM Article x INNER JOIN
    (SELECT t.article_id, COUNT(t.article_id)
      FROM articleTopics t
      WHERE t.topic_id IN ([your_list_of_topics])
      GROUP BY t.article_id
      HAVING COUNT(t.article_id)>=[number of elements in [your_list_of_topics]]
      ORDER BY COUNT(t.article_id) DESC
      LIMIT 0,100) AS ilv
    ON x.id=ilv.article_id
    

    Another advantage of this approach is that the structure of the query doesn’t need to change with the number of topics you are searching for – you could even put them in a temporary table and perform a join instead of using the ‘ IN (…)’ literal.

    You’d need to try it out to see which query behaves better.

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

Sidebar

Related Questions

This is a follow on from my last question relating to plotting timestamps in
Just saw this question relating to a segmentation fault issue in a C++ class
This might seem like a stupid question I admit. But I'm in a small
This is a difficult and open-ended question I know, but I thought I'd throw
This question comes from a need to ensure that changes I've made to code
Relating to a previous question, how let OSGi to reuse your configuration via Config
I want to do exactly what this question asks: Cascade Saves with Fluent NHibernate
I feel like every second question i ask here is relating to Facebook Connect
Ok, I have a question relating to an issue I've previously had. I know
This questions relating to infowindow in the google maps API v3.. Currently I loop

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.