tags:

views:

23

answers:

1
message table

id    user_id| message
 1       1   | this is my cruel message
 2       1   | this is my happy message
 3       2   | this is happy messgae    

message_tags table

id    message_id| tags
 1       2      | happy
 2       3      | happy

what i want to acess all the messages that have the the tag happy, how would construct the query in the best possible way :)) thanks

p.s. this is just an example database

+2  A: 
select m.id, m.user_id, m.message,
    u.Username 
from message m
inner join user_table u on m.user_id = u.id
where m.id in (select message_id from message_tags where tags = 'happy')
RedFilter
i love your answer thank you, can i just ask you how do you add another table in thier for `users_table` which reference the user_id in the messages table!! `user_table[id] ref messages[user_id]`
getaway
@getaway: see the update, above.
RedFilter
cheers redfilter, your a star!
getaway
Why mix "inner join" and "in ... select" styles? Presumably, a message won't have multiple "happy" tags.<code>select m.id, m.user_id, m.message, u.Username from message minner join message_tags t on m.id = t.message_idinner join user_table u on m.user_id = u.idwhere t.tags = 'happy'</code>
Simon
have you got a better alternative
getaway