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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:18:28+00:00 2026-05-27T10:18:28+00:00

what is the best model for a system of tags? for example, a topic

  • 0

what is the best model for a system of tags? for example, a topic can have N tags, tags and N may be related to N threads, if I create a table, tags and posts a table and this table tags, I had the ID of the posts, and the tag, would be duplicating many records as another topic to add this tag, which is the best way to avoid this?

enter image description here


@Quentin, the problem continues, it will repeat the records in the table post_tags

CREATE TABLE IF NOT EXISTS `posts` (
  `pid` bigint(22) NOT NULL AUTO_INCREMENT,
  `author` varchar(25) NOT NULL,
  `content` mediumtext NOT NULL,
  PRIMARY KEY (`pid`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

INSERT INTO `posts` (`pid`, `author`, `content`) VALUES
(1, 'Andrey Knupp Vital', 'Hello World !');

CREATE TABLE IF NOT EXISTS `tagged` (
  `pid` bigint(22) NOT NULL,
  `tid` bigint(22) NOT NULL,
  PRIMARY KEY (`pid`,`tid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `tagged` (`pid`, `tid`) VALUES
(1, 1),
(1, 2);

CREATE TABLE IF NOT EXISTS `tags` (
  `tid` bigint(22) NOT NULL AUTO_INCREMENT,
  `tag` varchar(15) NOT NULL,
  PRIMARY KEY (`tid`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

INSERT INTO `tags` (`tid`, `tag`) VALUES
(1, 'main'),
(2, 'hello');
  • 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-27T10:18:29+00:00Added an answer on May 27, 2026 at 10:18 am

    Use a junction table

    It will have at least two columns. “Posts” and “Tags” with the primary key being defined across the pair of them (if the database allows it, otherwise a third column for the primary key).

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

Sidebar

Related Questions

the best way to explain is with example so: this is the model public
Say I want to model a system where a piece of data can have
What are the best practices for using use cases to model system behavior that
What's the best lifetime model for a DataContext ? Should I just create a
I'm curious about what be the best way to model this for optimized performance...
I've been trying to figure out the best way to model this entity, and
I have Post model with published? field and some authorization system which defines admin?
An example system might require: Presentation/administration (ASP.NET MVC site) Object model for data access,
I think the best way to ask this question is with some code... can
I have always viewed tags as completely different than the normal folder hierarchy model.

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.