Re: Multiple entries in 1 field

From: J.O. Aho <user_at_example.net>
Date: Sun, 6 Oct 2019 10:00:14 +0200
Message-ID: <gvtl8fFh8anU1_at_mid.individual.net>


[Quoted] On 06/10/2019 05.39, groovee_at_cyberdude.com wrote:
> So, say I have a "stories" db, with fields such as storyid, storytext, dateposted, and category. Now under "category" I want it to have MULTIPLE CATEGORIES, ie. *one* story can be classified as "sci-fi" AS WELL AS "romance" AT THE SAME TIME!! But I would like it to be queryable, ie. if I want to find all the "sci-fi" stories in the db, I should be able to do so. How can I do this? (I would kind of not like to fiddle with raw data structures when doing this type of thing.... - is there some way COMPLETELY inside MySQL?)

[Quoted] [Quoted] The best way would be to have a stories_categories table, which just have two columns, one the storyid and the other categoryid. Making a joint primary key of both the storyid and cateoryid would make you safe [Quoted] from duplicate categories for stories.

If you have a newer mysql/mariadb, then you have json data type, it would be possible to use it to keep multiple values in one column, but you loose some sql power queries that you can use if you use two tables instead.

-- 

  //Aho
Received on Sun Oct 06 2019 - 10:00:14 CEST

Original text of this message