I'm building a guestbook feature for my website. I've got members, who are represented as records in the user database, and guests, obviously without entries in the user database.
I'm not sure how I should deal with these differences in the guestbook table.
I've got three columns in the table that's used to record who did the post:
user_id - which is a reference to members in the user database
guestname - which is used for guests who post
guestemail - which is used for guests who post
If there is a member who makes a post, I'll but her user_id in the user_id column, and leave guestname and guestemail empty. And vice versa for a guest.
Now, where I stumble is when I want to view the guestbook. I want a sql statement that retrieves name and email from the member table if user_id is set, and retrieves name and email from the guestbook table if user_id is empty. Can this be achived in a single statement? Or should I take a whole different approach to the problem?