MySQL: one or more rows?

I have any type of content that now has an identifier. I can specify several typesfor the content.

The question is should I use multiple lines to add multiple types or use a field typeand put the types there, separated by commas, and parse them intoPHP

A few lines

`content_id` | `type`

1            | 1
1            | 2
1            | 3

VS

Single line

`content_id` | `type`

1            | 1,2,3

EDIT


I am looking for a quick answer, but not easier, think about it. Performance is really important to me. So I'm talking about a really huge database with millionsor strings ten millions.

+3
source share
6 answers

" ", :

  • SQL , , WHERE type=3 , WHERE type LIKE '%3%',
  • - content_id type,
  • , " ", , .
  • / content_id type, , .
  • () , SQL , , PHP - ,

SQL , , .

+5

. , , , .

+4

. , type , . , .

+2
+2

. , . , / , . .

+1

, , .

- .

, , , . , . .

- , , type = 2? : " content_id mytable, type = 2". " content_id , " % 2% ". , 11 ? " 12 ". , " "%, 2,%". , , 2 . , LIKE % , .

? , , ?

? "" , , , . "select content_id, type_id, description from content join type using (type_id)". ... .

, ? , "3,7,9", "5". "3,7,9,5"? ? , , "1,2" "2,1" , . , SQL.

If there is some trivial gain, it is simply not worth it.

+1
source

Source: https://habr.com/ru/post/1763078/


All Articles