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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:32:30+00:00 2026-06-02T18:32:30+00:00

I have a database with primarily 3 tables, (ImageID, imageName), ( ImageID | Tags

  • 0

I have a database with primarily 3 tables, (ImageID, imageName), ( ImageID | Tags ) and (tagID, tagName)

So each image can have many tags associated to it. How would I efficiently and scale able select 1 image and find the next x images that are most similar ( have the same tags associated to it)

All done on the web using javascript, ajax and php. Thanks for any suggestions and hints on how to approach this!

Edit:

Yes Mysql

The format was ( Table ) and ( ROW | ROW )

IMAGEID, TAGID are primary keys

So yes there is a normalized index of IMAGEIDS and TAGIDS to save room.

I am trying to get if image A has 10 of 10 tags in common with image B it would be returned higher then IMAGE C which has 6 of 10 tags in common.

Sorry for being ambiguous.I am developing the site, so i can add keys, foreign keys, etc if its impossible to do it with what i have. And it doesnt have to be done in one giant SQL statement, i just dont want to get into a o(n^2) situation by comparing my first row to every other row 1 at a time.

  • 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-02T18:32:31+00:00Added an answer on June 2, 2026 at 6:32 pm

    Unfortunately this design isn’t actually very scalable. Simply because you really will be comparing the tags of one image against the tags of pretty much every other image.

    It’s codable, it’s just not overly scalable. (100’s of images? Great! Tens of thousands? You’ll be able to measure the lookup speed.)

    SELECT
      allImage.ImageID,
      COUNT(*)           AS commonTags
    FROM
      image_tag    AS allImage
    INNER JOIN
      image_tag    AS myImage
        ON allImage.TagID = myImage.TagID
    WHERE
      myImage.ImageID = 123
    GROUP BY
      allImage.ImageID
    ORDER BY
      COUNT(*) DESC
    

    Then use LIMIT or TOP (depending on your flavour of SQL) to pick only the first (N) images.

    NOTE: This assumes you don’t have all the tags for an image in a string held in one field of one row. If you do, you really should normalise the data to have one (ImageID,TagID) per row,

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

Sidebar

Related Questions

I have a very large database (~100Gb) primarily consisting of two tables I want
I have two database tables with the following structure: actions: action_id int(11) primary key
I have a MySQL database with 60 tables. Most of the tables have primary
In my database I have table AnimalDetails containing animalNumber(primary key),name,breed dateofbirth and an image
I have some databases that have four files each; one for PRIMARY, IDX, IMAGE,
I have database of about 5 tables. I am going to need to get
I have two database tables, one for Users of a web site, containing the
I have a database with two tables, PROCESS (PK Process_Id) and PROCESS_STAGE (PK Stage_Id,
I have a database in which all of the tables have been generated by
I am designing a new laboratory database. My primary data tables will have at

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.