Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Inner Join Help 1

Status
Not open for further replies.

overyde

Programmer
May 27, 2003
226
ZA
Hi,
I have two tables, namely "people" and "messages". I need to do a join between the two tables so that I can see who sent the message, who recived the message and the message details and ordered by the message receiver. Sample tables below:
Code:
+-----------------------------------------+
||   people                              ||
+-----------+--------------+--------------+
| person_id | person_fname | person_lname |
+-----------+--------------+--------------+
| 1         | Joe          | Bloggs       |
| 2         | Jane         | Doe          |
-------------------------------------------

+-----------------------------------------------------+
| messages                                            |
+-----------------------------------------------------+
| mess_id | mess_sender | mess_receiver| mess_message |
+---------+-------------+--------------+--------------+
| 1       | 1           | 2            | Hi how r u?  |
-------------------------------------------------------
So effectively I need it to read:
Joe Bloggs | Jane Bloggs | Hi how r u? |

What would be the correct syntax?

Reality is built on a foundation of dreams.
 
Code:
select concat_ws(' ',s.person_fname,s.person_lname) as sender 
     , concat_ws(' ',r.person_fname,r.person_lname) as receiver   
     , m.mess_message 
  from messages as m
inner
  join people as s
    on s.person_id = m.mess_sender     
inner
  join people as r
    on r.person_id = m.mess_receiver

r937.com | rudy.ca
 
You are the fishnizzle
:)

Reality is built on a foundation of dreams.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top