mysql query to display messages with sender and reciever -


my messaging schema

user   id   name  


message   id   messagetitle     sender_id     receiver_id   

i want display messagetitle sender , receivers name

for example mysql query should display :

+--------------+------------+--------------+ | messagetitle | sendername | recievername | +--------------+------------+--------------+ | important    | raj        | vijay        | | solution     | vijay      | raj          | +--------------+------------+--------------+ 

try following sql solution:

select      m.messagetitle messagetitle     ,u1.name sendername     ,u2.name recievername  message m  inner join user u1 on u1.id = m.sender_id  inner join user u2 on u2.id = m.receiver_id 

sql fiddle demo


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -