Join Sql Structure

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Join Sql Structure

    Helo there, i just wanna ask something about sql structure. . I am not familiar about "sql joining" so i never tried to code this.

    I have 3 tables named "1_group" and "2_group_member" and "3_message_from_a_group"

    1_group contains the "group_id", "title", "owner".

    And

    2_group_member contains "id", "group_id", "user_id", "accepted".

    And last

    3_message_from_a_group contains "id", "message", "author", "group_id".

    Now, i want that any user that was listed in 2_group_member wherein the value of accepted is 1/true will be able to see the content of 3_message_from_a_group.

    In short: before i can see the messages from that group, i should be a member.

    Could anyone help me please? Help me sql experts!
    It's n0t that i am afraid to die. Its just that if i die, wh0 wilL loVe her as muCh as i Do?

    #2
    personally i wouldnt use a join here as it is only causing your mysql to work hard then it needs to.
    eg:
    PHP Code:
    SELECT m.idm.messagem.author FROM 3_message_from_a_group m LEFT JOIN 2_group_member g ON m.group_id g.group_id AND g.user_id='".$uid."' AND g.group_id="'.$groupid.'" AND g.accepted=1 LIMIT 10 
    does mysql really need to check to see if your excepted in 10 rows? ^
    it really doesnt make sense to use a join here :/

    Comment


      #3
      Thankz bro. . . . I have observe the line "AND g.group_id='".$groupid."' AND" which is not supposed to be there?. . Cauz i want that the system will scan all the group table from the database not by a selected group only. . Cauz i want to make a wall that will list all the shouts from the groups i have joined.
      It's n0t that i am afraid to die. Its just that if i die, wh0 wilL loVe her as muCh as i Do?

      Comment


        #4
        Please help me guys...
        It's n0t that i am afraid to die. Its just that if i die, wh0 wilL loVe her as muCh as i Do?

        Comment


          #5
          Originally posted by analyzer View Post
          Thankz bro. . . . I have observe the line "AND g.group_id='".$groupid."' AND" which is not supposed to be there?. . Cauz i want that the system will scan all the group table from the database not by a selected group only. . Cauz i want to make a wall that will list all the shouts from the groups i have joined.
          SELECT m.id, m.message, m.author FROM 3_message_from_a_group m LEFT JOIN 2_group_member g ON m.group_id = g.group_id AND g.user_id='".$uid."' AND g.accepted=1 LIMIT 10

          Comment

          Working...
          X