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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:12:59+00:00 2026-06-08T04:12:59+00:00

I have a database that contains messages. The messages are stored in one table,

  • 0

I have a database that contains messages. The messages are stored in one table, the user information is stored in another. In the message table, there is an author_id column which represents the user_id of the author from the user table, there are all the message columns, and there is a to_address which represents a concatenation of “u_” + user_id from the user table. Is there any that I can join these two tables, so that it display the username instead of ID in BOTH the author_id AND to_address.

I’ve tried

SELECT  username, ..., username
  FROM msgs
    INNER JOIN users
      ON user_id=author_id AND concat("u_",user_id)=to_address;

with obvious error
I’ve tried using subqueries such as

SELECT
  ( SELECT username 
      FROM users
        INNER JOIN msgs
          ON user_id=author_id
  ) AS "From",
  ( SELECT username
      FROM users
        INNER JOIN msgs
          ON CONCAT("u_",user_id)=to_address
  ) AS "To",
  ( SELECT timestamp(message_time) FROM msgs
  ) AS "Sent",
  ( SELECT message_subject FROM msgs
  ) AS "Subject",
  ( SELECT message_text AS "Message" FROM msgs
  ) AS "Message"

and got “Subquery returns more than 1 row”. Is there any way that I can do this successfully?

  • 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-08T04:13:04+00:00Added an answer on June 8, 2026 at 4:13 am

    It sounds like you want something like this:

    SELECT
        from_user.username AS "From",
        to_user.username AS "To",
        timestamp(msgs.message_time) AS "Sent",
        msgs.message_subject AS "Subject",
        msgs.message_text AS "Message"
    
    FROM msgs
    
    INNER JOIN users AS from_user
    ON msgs.author_id = from_user.user_id
    
    INNER JOIN users AS to_user
    ON msgs.to_address = CONCAT("u_", to_user.user_id);
    

    Basically, you join the users table to the msgs table twice, giving each instance of the table a different name and a different join condition. Then you can pick a specific column out of a specific instance of the users table.

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

Sidebar

Related Questions

I have a SQLite database that contains a huge set of log messages. I
I have a database column that contains the contents of a file. I'm converting
I have a database table TravelRequest that contains, amongst other things, the fields SignOffName
I have a table that contains the following columns: @Column(name=CTDESTATUS) private String status; @Column
I have a Database that contains data about articles , structures and manufacturers .
I have a database that contains data for many clients. Currently, we insert tens
I have a database that contains a history of product sales. For example the
I have an xml database that contains films, for example: <film id=5> <title>The Avengers</title>
I have a database that which contains two tables, links and tour. Tour is
The code below works great. I have a MySQL database that contains book titles

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.