I\'m trying to mimic something similar to FB. Basically, users can post comments in various parts of a user\'s profile (e.g. \"wall\", a \"photo\", etc.). I think the following
You could have your table message, and then n:m relationship tables, i.e.
message_to_wall:
- messageID
- wallID
message_to_media:
- messageID
- mediaID
This way you keep the referential integrity and only have one message table.
This of course would technically allow it to have a message posted to a wall AND to a media item (photo, etc.). So you can't easily restrict this.
Otherwise - if you do not really require a relational database, you could think about using a NoSQL database like CouchDB or MongoDB. You can store all those comments right on the wall or media document. That way you don't have all those required JOIN queries and the comments are all linked to the media or wall.