1

I'm using PostgreSQL.

I have a table for a customers booking, Folio, that shows the staff ID of the staff that created the booking, and the ID of the most recent staff to change this booking.

I want to be able to, instead of showing these ID's, change them to show the name of the staff from my Staff table.

The fields in these tables are:

FOLIO:
CREATE_STAFF_ID, CHANGE_STAFF_ID

STAFF:
STAFF_ID, NAME

I've been trying something like:

SELECT (c.fields), p.CREATE_STAFF_ID, p.CHANGE_STAFF_ID, s.NAME
FROM OTHERTABLE c
JOIN FOLIO p ON (JOINING OTHERTABLE TO FOLIO TABLE)
JOIN STAFF s ON (p.CREATE_STAFF_ID = s.ALL_STAFF_ID)
WHERE (FILTERING);
1
  • Can you show us an example of what you're getting now, and what you would like to get? Commented Sep 1, 2016 at 19:24

1 Answer 1

1

if I'm getting what you mean it should show you the ID's and the NAMES for each ID:

SELECT f.create_staff_id AS staff_that_created_id
      ,a.name            AS staff_that_created_name
      ,f.change_staff_id AS staff_to_change_id
      ,b.name            AS staff_to_change_name
FROM folio f
LEFT JOIN staff a ON f.create_staff_id = a.staff_id
LEFT JOIN staff b ON f.change_staff_id = b.staff_id
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.