-1

I am creating a video player application with php and mysql.

The application has videos that are gathered in playlists like this:

Playlists table:

+----+------------------+------+
| id | name             | lang |
+----+-------------------------+
|  1 | Introduction     |   1  |
+----+-------------------------+

Videos table:

+----+--------------+-------------+
| id | name         | playlist_id |
+----+--------------+-------------+
|  1 | Video1       |           1 |
|  2 | Video2       |           1 |
+----+--------------+-------------+

It worked fine until now, because I need to build a searcher that finds videos depending on its name and language.

I though of creating another field called lang in the videos table, but then I realize that this maybe would contradict the normalization database rules. Because I would be repeating unnecessary information.

What can I do to select the videos without creating another field? Or do I need to create a new one with the repeated information?

EDIT: JOIN LEFT both tables is not a solution, because I maybe add in the future a new table that links to playlists such as courses.

2 Answers2

0

You can make LANGUAGE_ID COLUMN in Videos table,which will foreign key references to Playlists.lang .

Try above solution.

Hope this will help you.

Sagar Gangwal
  • 7,544
  • 3
  • 24
  • 38
0

You need to be clear about what attribute you want to assign to which entity (playlist, video or possibly course). You can assign language ids to both, playlist and video list items independently. Who is to say that you are not allowed to include a video with a language id of 2 in a playlist that carries a language id of 1? (This could, for example be a video in a foreign language that you want to appear in a playlist of your own language).

To search for suitable items you should then definitely use some kind of join (on video.playlist_id=playlist.id). The resulting table will contain both, video.language_id and playlist.language_id, which is not a case of having redundant information, as I have tried to explain above since they refer to different entities.

Carsten Massmann
  • 26,510
  • 2
  • 22
  • 43