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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:04:36+00:00 2026-05-19T12:04:36+00:00

I have this alogirthm problem, in terms of creating mysql tables, let me explain

  • 0

I have this alogirthm problem, in terms of creating mysql tables, let me explain the scenario:

I have a a posts table:

Posts{id, user_id,image,tag,date}

each post can only have on tag! ONLY

Do I need to have another table to store tags! I can understand if each post has more than one tag, you’d have to create another table for it to store the tags! but with this its only one!

i.e.

If I wanted to get all the posts with tag ‘DOG’ I would use:

select all posts where tag=DOG

do you think this is wrong or bad? I’m so confused!

  • 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-19T12:04:36+00:00Added an answer on May 19, 2026 at 12:04 pm

    If posts in your system will really only ever need to have one tag, then technically you can just hold the tag on the Post record. You shouldn’t, though: For example, what happens when you have 250000 posts about dogs, and decide to rename the “Dog” tag to “Canine”?

    A better idea is to create a Tag table and put a foreign key to it on the Post table. For example:

    Post{post_id, user_id, image, tag_id, date}
    Tag{tag_id, description}
    

    But just in case you’re really faced, someday, with a scenario in which a Post can have multiple Tags…

    Then you’re describing a model in which Posts and Tags exist in what’s called a Many-to-Many relationship: a given tag can be associated with any number of posts, and a given post can be associated with any number of tags.

    Now you not only need a separate table for Tags, but a relationship table in between that relates posts to tags. For example:

    Post{post_id, user_id, image, date}
    Tag{tag_id, description}
    
    Post_Tag{post_id, tag_id}
    

    You would then select all posts with the “Dog” tag like so:

    SELECT p.*
    FROM Post p
    JOIN Post_Tag pt ON pt.post_id = p.post_id
    JOIN Tag t ON pt.tag_id = t.tag_id
    WHERE t.description = 'Dog'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's a good algorithm to solve this problem? I have three groups of people
I have this idea for a free backup application. The largest problem I need
I'm trying to come up with a reasonable algorithm for this problem: Let's say
I've been bitten by this problem a couple of times and so have my
I found this algorithm here . I have a problem, I cant seem to
I have a language-agnostic question about an algorithm. This comes from a (probably simple)
I have this code in jQuery, that I want to reimplement with the prototype
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
I have this line in a javascript block in a page: res = foo('<%=
I have this setup where in my development copy I can commit changes on

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.