Two Foreign Keys refering to a primary key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sdsoderborg
    New Member
    • Oct 2019
    • 1

    Two Foreign Keys refering to a primary key

    Context: mysql

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

    PK: person_id,
    first_name,
    last_name.

    "Message" table

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

    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:

    Code:
    SELECT
    first_name AS "Sender's First Name", 
    last_name AS "Sender's Last Name"
    first_name AS "Receiver's First Name",
    last_name AS "Receiver's Last Name"
    FROM 
    message, person 
    WHERE 
    message.sender_id = 1 
    AND message.sender_id = person.person_id
    ???????;
    I need the query to list the first_name and last_name of both sender and receiver.

    Your assistance is appreciated.
    Last edited by gits; Oct 21 '19, 06:57 AM. Reason: added code tags
Working...