Implementation for tag based mail system by JOINS using MySQL Database
Problem:
I want to create a database table in which, I want to have an attribute called label. It should be able to have multiple values and if I want records, where label = value, it should come for all. I hope you understand my question.
Database / Table: Mails
Description
id – Primary Key, Integer, Autoincrement.
subject – Varchar, 50
label – should be an array of labels. Each may have different lengths. (i.e. a mail may contain 2 labels, another may have 5, another may don’t have any!)
Records
1, My first mail, {inbox, personal}
2, Welcome to our company, {official}
3, Mr. T has added you on this!, {friends, inbox}
Now if I give a command,
select * from Mails where label = inboxThe result should be
1, My first mail, inbox, personal
3, Mr. T has added you on this!, friends, inbox