[Answer]-Can you do this with a database?

1đź‘Ť

âś…

An alternative way to do something like this would be to use the GROUP_CONCAT function across the columns that differ, and group on the column(s) that repeat(s). This will create a delimited string column in the output that you will need to parse in PHP; however, it will reduce your row count to only the number of unique combinations of the non-grouped columns. For example:

select name, playlist, GROUP_CONCAT(file, '|', quality, '|', size, '|', type SEPARATOR '/') AS delimited_pairs
from video
group by name, playlist;

In the above example, the resulting delimited_pairs column will delimit each unique column value per name/playlist (the grouping columns) using the pipe character, and each of these unique combinations will be delimited by forward slash.

👤udog

0đź‘Ť

I think you have a problem with your data layout. Your “redundant data” shouldn’t go into the video_file table, but in the video table, as it is information referring to the video, not to the files! This database scheme is also bad in terms of cononsistency, if you eg. would update the the information in which playlist a video belongs you would have to do it for all the files…

Leave a comment