mySQL Quickly find rows linked to another row For example if I have a posts table with id and a likes table width id post_id user_id, how can I set up the database to organize the likes table by post_id in order so queries are faster? I can't make the post_id the primary key because there are more than one likes for each post.
Presumably, any given user can only like a given post once, so the likes table does not need and should not have an id column... Instead, define that table with PRIMARY KEY (post_id,user_id).  The likes for a given post will be quickly retrievable using the leftmost column of the primary key for lookups and you then have automatic prevention of duplicate likes for the same post by the same user as a secondary benefit.