Messaging system MYSQL, issue with getting latest reply -


i have table with

message_id, to_id, from_id, message

i made threaded messaging system. have 5 people talking 1 member.

as member see

member 1 says hi, member 2 says hello ( want latest reply hello )

member 1 says hi, member 3 says hi, member 1 says welcome ( want welcome )

member 2 says hi (i want hi )

now, i'm provided 1 of id's sessionid of member1. how go showing scenario 2 (member1) have left latest reply.

i can

 select * messages to_id=$session_id order message_id desc limit 1 

but show incoming messages. need show last of incoming , outgoing messages.

what query suggest? :\ maybe alteration table if there's no efficient way? first time i've ever setup messaging system, advice welcome.

select * messages to_id = $session_id or from_id = $session_id order message_id desc limit 1 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -