r/SQL • u/TheBatsnake • Sep 25 '26
PostgreSQL Help - Select statement: lookup value in joined table
Hello, I need help getting the output I need. So I have two tables one contains session details (Host id, Date/time, participant id). The other contains user ids and their emails. The users can be hosts or participants. I want to pull all the info from the first table but instead of showing the host id and participant id I want to join the user table and look up the email based on the id for both the host and participant column. So the final result would ne (Host email, Date/time, Participant email) instead of Ids.
0
Upvotes
9
u/reditandfirgetit Sep 25 '26
You do 2 joins with different aliases
3
u/SkullLeader Sep 25 '26
Select host.name as hostname, s.DateTime, participant.name
FROM SessionDetail s
INNER JOIN User host ON s.hostid = host.userid
INNER JOIN User participant ON s.hostid = participant.userid
1
u/bagelwithveganbutter Sep 28 '26
This sounds like a homework question
-7
u/[deleted] Sep 25 '26
[removed] — view removed comment