469,342 Members | 6,008 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

Two Foreign Keys refering to a primary key

Context: mysql

I have two tables.
"Person" Table with three fields

PK: person_id,

"Message" table

PK: message_id,
FK: receiver_id,
FK: sender_id,

The receiver_id and sender_id in the message table refer to
the person_id in the person table.

I want to write a query, using where clause (only), with the following format:

Expand|Select|Wrap|Line Numbers
  2. first_name AS "Sender's First Name", 
  3. last_name AS "Sender's Last Name"
  4. first_name AS "Receiver's First Name",
  5. last_name AS "Receiver's Last Name"
  6. FROM 
  7. message, person 
  8. WHERE 
  9. message.sender_id = 1 
  10. AND message.sender_id = person.person_id
  11. ???????;
I need the query to list the first_name and last_name of both sender and receiver.

Your assistance is appreciated.
Oct 19 '19 #1
0 2372

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Jeff Silverman | last post: by
1 post views Thread by Thomas T. Thai | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.