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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:23:46+00:00 2026-06-17T14:23:46+00:00

Suppose I have two table USER and MESSAGE USER – id,name MESSAGES – id,message_from,message_to,message_message

  • 0

Suppose I have two table USER and MESSAGE

USER -  id,name
MESSAGES - id,message_from,message_to,message_message

So inorder to join I use this co

SELECT m.*,u1.*,u2.* FROM MESSAGES m
    INNER JOIN USER as u1
       ON(m.message_from = u1.id)  
    INNER JOIN USER as u2
       ON(m.message_to = u2.id)

So now when i print_r out the result in codeigniter it doesn’t have the user data for the user message_to.

And I guess even if it return data for both user then it should have some prefixes to differentiate

So how should I do that ?

Thanks and Regards

  • 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-17T14:23:47+00:00Added an answer on June 17, 2026 at 2:23 pm

    It is best to avoid using SELECT * syntax.

    I would suggest you specify the columns you want back and give those columns whose names are not unique an alias.

    SELECT m.id AS MessageId,m.message_from,m.message_to,m.message_message,
        u1.id AS FromId, u1.name AS FromName,
        u2.id AS ToId,u2.name AS ToName FROM MESSAGES m
    INNER JOIN USER as u1 ON(m.message_from = u1.id)  
    INNER JOIN USER as u2 ON(m.message_to = u2.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 like these: USER id name MESSAGE id sender_id receiver_id As
Suppose I have two columns in a table that represents a graph, the first
Suppose we have two tables Foo and Bar. I have an association table Foo_Bar
I have a user table in my database which contains two columns FirstName and
I have a table name wishlist . In this I have two fields user_id
Suppose, I have two class named User and Authority. The specification of those two
Suppose I have following table in my database: Tbl_Persons: Id Country Name 1 Australia
Suppose I have two tables, which both have user ids. I want to perform
suppose i have a entity called USER and a relationship FRIENDSHIP exist between two
I have three tables, 1-Users, 2-Softwares, 3-UserSoftwares. if suppose, Users table having 6 user

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.