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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:13:21+00:00 2026-05-27T06:13:21+00:00

Assume I have a table that can have 0 or more tags: TABLE: foo

  • 0

Assume I have a table that can have 0 or more tags:

TABLE: foo
- foo_id (PK)

TABLE: tag
- tag_id (PK)
- name

TABLE: foo_tag
- foo_tag_id (PK)
- foo_id (FK)
- tag_id (FK)

Questions:

  1. The above is the most common and simplest way to implement a tagging system that I have seen. I do realize that there are potential problems with tagging systems in terms of scalability. Am I going to have that here?
  2. Is there a way to do something like this in PHP or SQL: insert a new tag “bar”. If “bar” does not exist, add it to the tag table and return the last inserted id. If “bar” does exist, do not add it and return the tag_id for it.
  3. Is there a “proper” DB term for such a table describe in #2?
  • 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-27T06:13:21+00:00Added an answer on May 27, 2026 at 6:13 am

    Please see http://dev.mysql.com/doc/refman/4.1/en/insert-on-duplicate.html for a workaround to get the last ID on update:

    INSERT INTO table (a,b,c) VALUES (1,2,3)
      ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), c=3;
    

    This will update the last insert id to the value of the updated value. In your case:

    INSERT INTO tag (name) VALUES ('bar')
      ON DUPLICATE KEY UPDATE tag_id=LAST_INSERT_ID(tag_id);
    

    tag.name needs to be a unique key.

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

Sidebar

Related Questions

To illustrate, assume that I have two tables as follows: VehicleID Name 1 Chuck
Assume I have a table called table and I have 3 columns, a, b,
Assume I have the following style table, col1 col2 and col3 have same value
Assume I'm indexing a table of books. They have title, author, description, etc. I
Assume I have a class foo, and wish to use a std::map to store
Assume you have some objects which have several fields they can be compared by:
Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
I have a question that is more in the realm of design, than implementation.
I would like to know how this can be achieved. Assume: That there's a
Assume that I have two parent tables: Company and Contact . Assume that both

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.