r/SQL • • 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 comments sorted by

9

u/reditandfirgetit Sep 25 '26

You do 2 joins with different aliases

3

u/s3kshun18 Sep 25 '26

Exactly that. Name one join host and the other participant (h and p) and bring back p.email as participantEmail and h.email as hostEmail.

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

5

u/WolfBanner Sep 26 '26

Why spend money on AI Tokens when you can ask Reddit? You get to save the tokens, interact with a community, and trigger people who think there is only one way to do things, all at the same time. I say: ask Reddit and enjoy some popcorn while people fight it out.

3

u/TheBatsnake Sep 26 '26

Yeah, I'm in no rush, plus I like asking people, nothing wrong with that. This isn't some kind of race where I need an answer as fast as possible. Also ai has been completely wrong or doesn't understand issues for previous concepts I've used it for in my coding. I just want a sql query and how to do this specific thing and I chose to ask people. Your comment makes so many assumptions about a person you know little of.

6

u/Plus_Dragonfruit_204 Sep 26 '26

Since when is AI infallible? If you don't understand how to do the basics, how can you determine when what AI gave you is wrong?

There's never anything wrong with asking questions and learning.

Giving someone the answer only does there job for them, teaching them how to do it gets them to the point of not having to ask the same question again.