Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2009

    Red face Unanswered: Fetching data of each user for each forum thread message?

    Hi people, as I'm designing my own forum database (okay there were reasons behind this) with Microsoft SQL Server 2008, there is something got me very concerned -- performance. Consider the following basic table to store thread messages in the forum:

    Table: Messages
    mid: Message ID (Primary key)
    uid: User ID (Foreign key to Users table)
    tid: Thread ID (Foreign key to Threads table)
    msg: Message content
    Table: Users
    uid:   User ID (Primary key)
    name:  User name
    posts: Number of posts user has made
    sig:   User signature to show on messages
    When I'm displaying messages of one given thread 1234, I'll do a "SELECT * FROM Messages WHERE tid = 1234". That is one query, and then for each of the messages, I need to display user info (e.g. user name, signature, etc...). If there are 10 unique users for the given thread, then I need to make ten additional queries to obtain their information (just to display one thread). I imagine I can do all that with one Stored Procedure, but ultimately there are still 11 queries for this case.

    Will that not kill my DB server? Is this considered normal? I'm sorry if I have missed obvious shortcuts, I'm just yet another C++ guy, SQL is not my mother tongue

    Thanks in advance,

  2. #2
    Join Date
    Nov 2009


    Oops, apparently I need to start working on my SQL skill set, there is a JOIN statement so it works like this:

    SELECT Messages.msg,, Users.posts, Users.sig
    FROM Messages INNER JOIN Users ON Messages.uid = Users.uid

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts