Favouriting things in a database - most efficient method of keeping track?

Posted by a2h on Stack Overflow See other posts from Stack Overflow or by a2h
Published on 2010-04-13T02:33:21Z Indexed on 2010/04/13 2:42 UTC
Read the original article Hit count: 261

Filed under:

I'm working on a forum-like webapp where I'd like to allow users to favourite an item so that they can keep track of it, and also so that others can see how many times an item's been favourited.

The problem is, I'm unsure on the best practices for databases, which includes this situation.

I have two ideas in my head on how to do this:

  1. Add an extra column to the user table and store things like so: "|2|5|73|"
  2. Add an extra table with at least two columns, one for referencing an item, the other for referencing a user.

I feel uncomfortable about going for the second method as it involves an extra table, and potentially more queries would be required. Perhaps these beliefs aren't an issue, as I have little understanding of databases beyond simply working with table layouts and basic queries.

© Stack Overflow or respective owner

Related posts about mysql