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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:19:00+00:00 2026-05-11T13:19:00+00:00

I’ll try to explain my case as good as i can. I’m making a

  • 0

I’ll try to explain my case as good as i can. I’m making a website where you can find topics by browsing their tags. Nothing strange there. I’m having tricky time with some of the queries though. They might be easy for you, my mind is pretty messed up from doing alot of work :P.

I have the tables ‘topics’ and ‘tags’. They are joined using the table tags_topics which contains topic_id and tag_id. When the user wants to find a topic they might first select one tag to filter by, and then add another one to the filter. Then i make a query for fetching all topics that has both of the selected tags. They might also have other tags, but they MUST have those tags chosen to filter by. The amount of tags to filter by differs, but we always have a list of user-selected tags to filter by. This was mostly answered in Filtering from join-table and i went for the multiple joins-solution.

Now I need to fetch the tags that the user can filter by. So if we already have a defined filter of 2 tags, I need to fetch all tags but those in the filter that is associated to topics that includes all the tags in the filter. This might sound wierd, so i’ll give a practical example 😛

Let’s say we have three topics: tennis, gym and golf.

  • tennis has tags: sport, ball, court and racket
  • gym has tags: sport, training and muscles
  • golf has tags: sport, ball, stick and outside

    1. User selects tag sport, so we show all three tennis, gym and golf, and we show ball, court, racket, training, muscles, stick and outside as other possible filters.
    2. User now adds ball to the filter. Filter is now sport and ball, so we show the topics tennis and golf, with court, racket, stick and outside as additional possible filters.
    3. User now adds court to the filter, so we show tennis and racket as an additional possible filter.

I hope I’m making some sense. By the way, I’m using MySQL.

  • 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. 2026-05-11T13:19:01+00:00Added an answer on May 11, 2026 at 1:19 pm
    SELECT DISTINCT `tags`.`tag` FROM `tags` LEFT JOIN `tags_topics` ON `tags`.`id` = `tags_topics`.`tag_id` LEFT JOIN `topics` ON `tags_topics`.`topic_id` = `topics`.`id` LEFT JOIN `tags_topics` AS `tt1` ON `tt1`.`topic_id` = `topics`.`id` LEFT JOIN `tags` AS `t1` ON `t1`.`id` = `tt1`.`tag_id` LEFT JOIN `tags_topics` AS `tt2` ON `tt2`.`topic_id` = `topics`.`id` LEFT JOIN `tags` AS `t2` ON `t2`.`id` = `tt2`.`tag_id` LEFT JOIN `tags_topics` AS `tt3` ON `tt3`.`topic_id` = `topics`.`id` LEFT JOIN `tags` AS `t3` ON `t3`.`id` = `tt3`.`tag_id` WHERE `t1`.`tag` = 'tag1' AND `t2`.`tag` = 'tag2' AND `t3`.`tag` = 'tag3' AND `tags`.`tag` NOT IN ('tag1', 'tag2', 'tag3') 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.