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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:23:24+00:00 2026-06-11T17:23:24+00:00

still trying to get started in the world of databases, running into issues daily!

  • 0

still trying to get started in the world of databases, running into issues daily!

I have a table ‘songs’ which contains information on artists/tracks:

CREATE TABLE songs (
    song_id INT AUTO_INCREMENT PRIMARY KEY, 
    artist_name varchar(100) DEFAULT NULL,
    song_name varchar(100) DEFAULT NULL,
    tag_fk SMALLINT,
    FOREIGN KEY (tag_fk) REFERENCES tags(tag_id) ON DELETE SET NULL ON UPDATE CASCADE,
) ENGINE = 'InnoDB';

CREATE TABLE tags (
    tag_id SMALLINT AUTO_INCREMENT PRIMARY KEY,
    tag_name varchar(255) UNIQUE
) ENGINE = 'InnoDB';

Now I have a foreign key in ‘songs’ referencing ‘tags.tag_id’, ‘tags.tag_name’ will later contain tags like ‘lovesong’, ‘melancholic’. Now in certain cases a song can have more than one tag, so if its a melancholic lovesong it should have both tags. Though I just noticed I can not add two SMALLINT to tag_fk seperated by comma, it only allows one SMALLINT per row.

I figured I could add a new row to ‘tag.tag_name’ containing ‘lovesong;melancholic’ and later process it in php, splitting it by ‘;’, but that is rather a less sexy solution to the problem, especially because the data is added by a program and I would have to deal with sorting the strings, too, so I wouldn’t end up with duplicate tags like ‘lovesong;melancholic’ and ‘melancholic;lovesong’, which is basically the same.

How is that issue commonly solved? If I do replace ‘songs.tag_fk’ by a varchar column ‘songs.tag’ instead I will have tons of duplicate data, as there’s gonna be a lot of “Lovesongs” and “Melancholic” songs in the database, so a foreign key solution is probably best.

I also thought about adding ‘songs.tags_fk’ and ‘songs.tags_fk2’ but thats rather a dirty hack, too. Especially if some songs start having more than 2, 3, 4 tags.

What’s the best way to deal with that?

  • 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-06-11T17:23:25+00:00Added an answer on June 11, 2026 at 5:23 pm

    Sounds like a many-to-many relationship. You require a third table to link the two. So that one song can have many tags, and one tag can be assigned to many songs.

    http://www.phpknowhow.com/mysql/many-to-many-relationships/

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

Sidebar

Related Questions

Sometimes I still get stuck trying to translate procedural code into functional code. Is
I have been trying different things and still have been able to get exactly
I'm still trying to get a hang of Perl's OOP features. I'm confused about
I'm still trying to get my feet on the ground with Silverlight and RIA
I'm still trying to get the hang of SQL. I built 1 query that
So I'm still trying to get comfortable using Parsec, but I'm slowly working it
I am a bit puzzled with my Regex results (and still trying to get
Just trying to still get my head around IOC principles. Q1: Static Methods -
I am trying to get partitioned views to work, and still see query optimizer
I've been trying to get this Sudoku game working, and I am still failing

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.