Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make join for few columns in same table in postgres?

I have a table.
The table has several columns with user ids.
There is only one table with users.
enter image description here

If there was one column, then everything is clear, we do join user_id = users.id and then use users.name.
What if there are multiple columns? How can I do a join on each of the columns?
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can join the same table using different aliases.

select adduser.name as adduser,
    edituser.name as edituser, 
    deluser.name as deluser
from table as t
join users as adduser
    on t.adduser_id = adduser.id
join users as edituser
    on t.edituser_id = edituser.id   
join users as deluser
    on t.deluser_id = deluser.id

        
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading