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 8640841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:22:38+00:00 2026-06-12T11:22:38+00:00

Table_Users id username 1 Jack 2 Marine 3 Katie 4 Hennry Table_Messages id to_id

  • 0
Table_Users
id  username
1   Jack
2   Marine
3   Katie
4   Hennry

Table_Messages
id  to_id   from_id Messages
1   2   3   Hello
2   3   2   Hi

Need a single query which can return a Message, To Name and From Name

  • 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-12T11:22:39+00:00Added an answer on June 12, 2026 at 11:22 am

    You need to join the table users on table messages twice since you need to get the equivalent names for to andfrom users.

    SELECT  a.id,
            b.`username` TO_NAME,
            c.`username`  FROM_NAME,
            a.Messages
    FROM    tbl_Messages a
            INNER JOIN users b
                on a.to_ID  = b.id
            INNER JOIN users c
                on a.from_ID = c.id
    

    See SQLFiddle Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a mySQL database with a 'users' table which includes a username,
I have a MYSQL table like this example: [ID]--[Date]--[UserID]--[Username]--[String] 1 12-10-06 02:35:01 25 Jack
i have a user table id , username 22 , max 33 , jack
Is this possible to do this in one MySQL query? Basically I need to
I have Two tables. 1.Users table (Username , Name) 2.Picture table( ID , Username
I have table users with columns id, username, email and password. And i have
users table +-----+-----------+ | id | username | +-----+-----------+ | 1 | tom |
I am wondering if the aspnet_Users table is always sorted (by UserName) even if
I have a table of users with three columns. Username Accepted Rejected User 1
i have a table that holds my users information like username , password ,

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.