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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:43:22+00:00 2026-05-25T02:43:22+00:00

Im trying to implement small project where people can set tags for certain items

  • 0

Im trying to implement small project where people can set tags for certain items and similar tags will be displayed on the page.

example:

Table : item_data
row 1:

item_id = 1 (event)
Tags = "Rugby, Tickets, Give away, Sesssions, Prizes"

row 2:

item_id = 2 (Ticket booking)
Tags = "New Zeland, Travel, Booking, Tickets, Rugby"

row 3:

item_id = 3 (car for sale)
Tags = "New Zeland, Blue, Ford, Sedan"

is there away purely in SQL to to get all matching item_ids for a given set of tags.
take the tags data from row 1 and find all the matching records for each tag in all the other rows?

I can do this with a mix of php and mysql, i was wondering if anyone have a better way to do this on sql alone.

  • 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-25T02:43:23+00:00Added an answer on May 25, 2026 at 2:43 am

    I would recommend using Data Normalization (http://www.bkent.net/Doc/simple5.htm). if you are keeping tags in string formats like “tag a, tag b tag c, etc” then you have to select every tag in the DB break them in to arrays and do matching on that in order to find the relavant data.

    I would recommend making a table for the Items and another for Tags that will grow as new tags are added then a third table mapping the item_id to the tag. Once this is done you can select based off specific tags and groups of tags to get results.

    |Item_table               |
    |-------------------------|
    |item_id | Desc           |
    |1       | Event          |
    |2       | Ticket Booking |
    |-------------------------|
    
    |Tag_Table   |
    |------------|
    |id  | tag   |
    |1   | Rugby |
    |2   | Blue  |
    
    |Tag_Map                  |
    |-------------------------|
    |id    | tag id | item id |
    |1     | 1      | 1       |
    |2     | 1      | 2       |
    

    You would create an index in the map table and the tag table. and you would use this like so:

    SELECT it.Desc FROM Item_Table it, Tag_Table tt, Tag_Map tm WHERE tt.id = tm.tag_id AND it.item_id = tm.item_id and (tt.tag = "Rugby" or tt.tag = "Blue");
    

    you would only have to change the last part in () to one tag or keep adding “or” and another tag, that will give you any and all item descriptions that match any given tag.

    I know 3 tables looks like a lot to manage but trust me, if you item table and tag table begin to grow to the tens of thousands you (and you mysql server) will appreciate this style of data storage.

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

Sidebar

Related Questions

For a project of mine, I'm trying to implement a small part of the
Trying to implement a UITableView of names similar to the built-in Contacts iPhone app
While trying to implement an MVC file upload example on Scott Hanselman's blog. I
im trying to implement a custom error page, what i want to be able
We are in the process of trying to implement perforce in our small IT
I'm trying to implement a small ASP.NET MVC site which interacts with another site.
Trying to implement the example from here. Facebook Share passes along the URL of
We are about to implement a small automated securities trader. The trader will be
I'm trying to implement this in a small ruby script, and tested it on
I am trying to implement a very simple little dropdown-style mini-menu that will appear

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.