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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:31:48+00:00 2026-05-27T07:31:48+00:00

I have categories and multiple categorization for my Items. How to find, for specific

  • 0

I have categories and multiple categorization for my Items. How to find, for specific Item, other Items that have same categories, ordered by most categories matching (aka best match)?

My table structure is roughly:

Item Table

ID
Name
...

Category Table

ID
Name
...

Categorization Table

ID
Item_ID
Category_ID
...

To find all Items having similar categories, for example, I use

SELECT `items`.* 
FROM `items` 
INNER JOIN `categorizations` c1
ON c1.`item_id` = `items`.`id`
INNER JOIN `categorizations` c2
ON c2.`item_id` = <Item_ID>
WHERE `c1.`category_id` = c2.`category_id`
  • 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-27T07:31:49+00:00Added an answer on May 27, 2026 at 7:31 am

    This should produce a table of counts of category matches between each pair of items that share at least one category.

    select i1.item_id,i2.item_id,count(1)
    from items i1
    join categorizations c1 on c1.item_id=i1.item_id
    join categorizations c2 on c2.category_id=c1.category_id
    join items i2 on c2.item_id=i2.item_id
    where i1.item_id <> i2.item_id
    group by i1.item_id,i2.item_id
    order by count(1)
    

    I suspect that it may be a bit slow, though. I don’t have an instance of MySQL at the moment to try it out.

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

Sidebar

Related Questions

I have tables with listings, categories and one that maps them to each other.
Say you have a Book model that can belong to multiple categories. Categories are
I have an e-commerce system that allows a product to have multiple categories. In
I have a page that will pull many headlines from multiple categories based off
I have a form that has multiple categories. They are separated by checkboxes, so
I have several categories that I use in my Grails plugin. e.g., class Foo
I have a Categories table in which each category has a ParentId that can
I need get all items these have no categories int? categoryId = null; var
I have about 200 categories that are nested. I am currently reading the documention
Say I have some 10 categories that I need to reference in a web

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.