Join Sql Structure

Started on the old forum in April 2012 · view the original in the archive · old links redirect here

4 replies · 456 views · started 14 years ago · 1 min read

2 participants
analyzer Developer · 104 posts #1

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?

something else Fellow · 2,296 posts #2

personally i wouldnt use a join here as it is only causing your mysql to work hard then it needs to. eg:

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.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 :/

analyzer Developer · 104 posts #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?

analyzer Developer · 104 posts #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?

something else Fellow · 2,296 posts #5

analyzer wrote: 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

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close