0

I am have table a that stores created_by and updated_by while both of them just store user_id, while I have table b that stores user_id, and user_name. I cant seems to retrieve the same column with two different criteria. I have two sql that but how to combine both of them

SELECT b.user_name FROM a.created_by WHERE b.created_by = a.user_id
SELECT b.user_name FROM a.updated_by WHERE b.updated_by = a.user_id
  • look what is join https://stackoverflow.com/questions/38549/what-is-the-difference-between-inner-join-and-outer-join and really read basic sql curse because none of your queries are ok. you can not read from field `FROM a.created_by` – Livius Jun 30 '18 at 10:01

2 Answers2

0

I am not absolutely sure about your table structure, but it seems to me you want to do something like

SELECT u.user_name createdBy, v.user_name changedBy
FROM tablea t 
INNER JOIN tableb u ON u.user_id=t.created_by
INNER JOIN tableb v ON v.user_id=t.changed_by
Carsten Massmann
  • 26,510
  • 2
  • 22
  • 43
0

I didn´t really understand much of your question, but i think you want to mix the two queries in one:

SELECT b.user_name 
FROM a 
     join b on (a.user_id=b.created_by or  a.user_id=b.updated_by)
nacho
  • 5,280
  • 2
  • 25
  • 34