Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9294973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:29:40+00:00 2026-06-18T21:29:40+00:00

I have tables that look like this: create table users ( user_id uuid, user_name

  • 0

I have tables that look like this:

create table users (
    user_id uuid,
    user_name varchar(32)
);

create table messages (
    message_id uuid,
    from_id uuid references users(user_id),
    to_id uuid references users(user_id),
    the_message varchar(140),
    primary key(message_id)
);

If I do the following:

select * from messages

I will be given UUIDs. I want to display the users.user_name for the given uuid. This gets me close:

select
    users.user_name as from_id,
    users.user_name as to_id
from messages
    join users on users.user_id = messages.from_id
;

The result displays the same user for both the “from” and the “to” field.

How do I display the user_name for the from_id, and also the user_name for the to_id?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T21:29:41+00:00Added an answer on June 18, 2026 at 9:29 pm

    You need to JOIN the users table twice — once for the from user and once for the to user:

    select
        messages.*,
        f.user_name as from_id,
        t.user_name as to_id
    from messages
        join users f on f.user_id = messages.from_id
        join users t on t.user_id = messages.to_id
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that look like this: CREATE TABLE table1 (user_id int, the_date
I have two tables in my database that look like this CREATE TABLE IF
I have three tables...users, user_info, and quota_levels. They look like this: CREATE TABLE users
i have a table called users this what the table look like CREATE TABLE
Let's say I have two tables that look like this: TH TH TH TH
I have a 3 tables that look like this: (source: InsomniacGeek.com ) On the
I have a table posts that could look like this: id | title |
On my pages I have a table with rows that typically look like this:
I have a number of mappers that look like this: mapper(Photo,photo_table, properties = {
I have two tables in my database that look like that: Customer: C_ID city

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.