Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL Database Structure for Followers
    primarykey
    data
    text
    <p>I would like to implement a follow/favorite system. I can think of 2 ways of implementing a database/table structure but am unsure of which one to implement. Which one of these would be considered best practices and most importantly why?</p> <p>I put all of my followers in a single string. By putting all followers in a single string it reduces the amount of redundant rows.</p> <p>Ex.</p> <p>id (1) || user_id (1) || follower_ids (2, 3, 45)</p> <pre><code>'CREATE TABLE `users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(20) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'; 'CREATE TABLE `follow` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL, `follower_ids` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'; </code></pre> <p>OR</p> <p>I put each follow_id individually but adds redundancy by having 3 rows for the same user_id.</p> <p>Ex.</p> <p>id (1) || user_id (1) || follower_id (2)</p> <p>id (2) || user_id (1) || follower_id (3)</p> <p>id (3) || user_id (1) || follower_id (45)</p> <pre><code>'CREATE TABLE `users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(20) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'; 'CREATE TABLE `follow` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL, `follower_id` int(10) unsigned NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1'; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload