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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:36:27+00:00 2026-06-16T01:36:27+00:00

I am working on an application that will do some sort of smart data

  • 0

I am working on an application that will do some sort of smart data search by disabling unrelated tags in a search pool.

For example (sorry if my formatting may be crappy), given this table:

    _id  |  _tagname
    1       A
    1       B
    1       C
    2       A
    2       B
    3       A
    4       B
    5       C
    6       D

when the user select tag A, (the following will be performed on each tag selection):

  1. Fetch ID’s that will match the tag -> 1, 2, 3 which will now be the new search pool
  2. Hide all tags that will not be relevant -> D since tag B and C will allow the user to filter the tags to get ID 1

TL;DR: This is my current approach and I was wondering if there are ways to optimize it because currently it is taking too long to get the results

SELECT _tagname FROM datatags WHERE 
(_tagname) NOT IN 
( SELECT _tagname FROM datatags WHERE 
_id IN (1,2,3)) 
GROUP BY _tagname

Thank you! This is my first time posting a question so please take it easy on me 🙂

Edit: formatting

  • 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-16T01:36:28+00:00Added an answer on June 16, 2026 at 1:36 am

    Are you ultimately looking for the tags that appear together, or do you really want the odd tags out?

    Here are two ways to find the related tags (returns { A, B, C } for A or B or C, and returns { D } for D)

    • Use a correlated subquery:

      SELECT DISTINCT _tagname 
      FROM   datatags 
      WHERE  _id IN (SELECT _id 
                     FROM   datatags 
                     WHERE  _tagname = ?)
      
    • Use a self join:

      SELECT DISTINCT b._tagname 
      FROM   datatags a 
             JOIN datatags b USING (_id) 
      WHERE  a._tagname = 'A' 
      

    For the inverse (tags that never appear with the given tag), you’d find the difference between the entire set of tags and the related tags. MySQL doesn’t support MINUS, but here one way to find the unrelated tags:

    • Use a correlated subquery with a self join:

      SELECT _tagname 
      FROM   datatags 
             LEFT JOIN (SELECT DISTINCT _tagname 
                        FROM   datatags 
                        WHERE  _id IN (SELECT _id 
                                       FROM   datatags 
                                       WHERE  _tagname = ?)) a USING (_tagname) 
      WHERE  a._tagname IS NULL
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an application that will perform a search against an online
I'm working on an application that will have attachments, and I would like to
I am working on web application that will use PHP & MySQL. Application will
I am currently working on an application that will retrieve other users' locations based
I'm working on a web application that will have a custom UI for the
I'm working on a desktop application that will produce several in-memory datasets as an
We are working on a Vista/Windows 7 application that will be running in 64
I'm working on a Rails 3.2 application that will allow users to authenticate with
I am working on an application at the minute that will originally be just
I'm working on an intranet-only web application (J2EE) that requires some basic security features.

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.