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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:33:10+00:00 2026-05-17T01:33:10+00:00

based on How to implement tagging system similar to SO in php/mysql? ive made

  • 0

based on How to implement tagging system similar to SO in php/mysql?

ive made small changes, and have the following image tag implementation:

SELECT I.imageId, GROUP_CONCAT(DISTINCT T.tagName SEPARATOR ' '), COUNT(*)
FROM Images I
INNER JOIN ImageTagMap M ON I.imageId = M.imageId
INNER JOIN ImageTags T ON T.tagId = M.tagId
WHERE T.tagName LIKE '%new%' OR T.tagName LIKE '%yo%'
GROUP BY I.imageId
ORDER BY COUNT(*) DESC

currently, this successfully gets the imageId’s of all of those images that fullfil the WHERE clause, and orders them according to the most hits (no. hits being generated by the GROUP BY clause). it also gets all the matched tag names and sticks them in a single string. nice.

what i would really like for the user, is to have all the tagNames for the relevant picture. currently the tagNames returned are only those that matched with the LIKE statements. e.g. if a picture is tagged “2010 new york” and i search (as above) “new yo” it will return imageId, “new york”. but i want all the tag info for the matched image, i want imageId, “new york 2010”.

a simple solution would be to stick the above query in a subquery and rerun the join with a new WHERE clause of imageId IN( above query as subquery ). although that seems silly (even if the optimiser might do magic with it), surely i dont need to rerun the exact same join twice? or do i?

as an aside, is there a better way to search tags than the bunch of LIKE’s ive stuck in?

  • 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-17T01:33:10+00:00Added an answer on May 17, 2026 at 1:33 am

    SELECT
    M.imageId,
    GROUP_CONCAT(DISTINCT T2.tagName SEPARATOR ' ') AS tagNames,
    COUNT(DISTINCT T.tagName) AS relevance
    FROM ImageTagMap M
    JOIN ImageTags T ON T.tagId=M.tagId
    JOIN ImageTagMap M2 ON M2.imageId=M.imageId
    JOIN ImageTags T2 ON T2.tagId=M2.tagId
    WHERE T.tagName LIKE '%new%' or T.tagName LIKE '%yo%'
    GROUP BY M.imageId
    ORDER BY relevance DESC

    had to rejoin twice. any shorter ways are welcome.

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

Sidebar

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.