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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:28:46+00:00 2026-06-12T19:28:46+00:00

I have two tables objects and tags , each object having an id, and

  • 0

I have two tables objects and tags, each object having an id, and each tag having an id a name and a parent (the id of the object).

What I want to do is to choose an object then find other objects ordered by the amount of tags in common , e.g. to return the 5 most similar objects.

EDIT:

SELECT parent,COUNT(*) as count
FROM `tag` 
WHERE tag="house" OR tag="dog" OR tag="cat" 
GROUP BY parent 
ORDER BY count DESC

This one does what I want, and I could find the obejcts tags “house,dog,cat” with another query before this one. Any idea how I could combine these two queries?

  • 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-12T19:28:48+00:00Added an answer on June 12, 2026 at 7:28 pm

    Given one object, you can find its tags like this:

     SELECT t1.id
     FROM tags t1
     where t1.parent_id = ?
    

    Building on that, you want to take that list of tags and find other parent_ids that share them.

     SELECT parent_id, count(*)
     FROM tags t2
     WHERE EXISTS (
         SELECT t1.id
         FROM tags t1
         WHERE t1.parent_id = ?
         AND t1.id = t2.id
     )
     GROUP BY parent_id
    

    That will give you a count of how many tags those other parent_ids share.

    You can ORDER BY count(*) desc if you’d like to find the “most similar” rows first.

    Hope that helps.

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

Sidebar

Related Questions

I have two tables without any cascade deleting. I want to delete parent object
I have two tables: Persons: (Id, Name) Addresses: (Id, Address, PersonID) It means each
Say I have two tables: object id name object_event id object_id type date I
I have two tables: objects object_features ------------- ------------------- id id name object_id term_id What
I have two tables: object that has object_id column and avalues that have object_id
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables user table user_id | name | 1 | peter |
I have two tables, that share the same definition. I commonly insert new objects
I currently have two tables, one for pages (objects) and one for images (media).
Pretty complicated... I have two tables, t1 which contains descriptive information regarding specific objects,

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.