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

  • Home
  • SEARCH
  • 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 1063167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:44:37+00:00 2026-05-16T18:44:37+00:00

user_table user_id | username 1 | solomon 2 | muna message table id user_id|

  • 0

user_table

 user_id | username
       1 | solomon
       2 | muna

message table

id    user_id| message
 1       1   | this is my first message
 2       1   | this is my seocnd message
 3       2   | this is muna messgae    

relationship table

  leader | follower
       1 | 2
         |    

what i want to do is a three table join to bring out muna’s friend messages, currently muna is following solomon(as shown on the followers table),

so i want the display to be like this on mona homepage

Solomon "this is my my first message
----------------------------------
solomon "this is my second message"

p.s. this is just an example database, i just wanted to see how to approach the problem, and this is what i have attempted so far!

 select username, message, leader
    from user, message, relationship where user.user_id =notes.user_id 
and user.user_id = relationship.leader and where user_id = $_SESSION['user_id']

*the session id is muna which is user_id 2

  • 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-05-16T18:44:38+00:00Added an answer on May 16, 2026 at 6:44 pm

    heres one way of doing it

    SELECT m.message,u.username FROM relationships r, messages m,users u WHERE m.user_id = r.leader AND r.leader = u.user_id AND u.user_id = 1
    

    Spaced out

    SELECT
        m.message,u.username #here you can use m.* to retrieve all data
    FROM
        relationships r,     #Here you can define what tables you want to use
        messages m,          #within your query, always remember to do table_name letter
        users u              #this will stop ambiguity within the queries 
    WHERE
        m.user_id = r.leader #make sure the message user id is the same as the leader id
    AND
        r.leader = u.user_id #same as above just making the messages be filtered to the user_id 
    AND
        u.user_id = 1        #your overall id will be here, if this was 2 it would affect WHERE, and AND above.
    

    Within application

    $query = mysql_query('SELECT m.message,u.username FROM relationships r, messages m,users u WHERE m.user_id = r.leader AND r.leader = u.user_id AND u.user_id = ' .  intval($_SESSION['user_id']));
    
    while($row = mysql_fetch_assoc($query))
    {
        echo sprintf("%s: %s",$row['username'],$row['message']);
        echo "\r\n--------------------------------------------";
    }
    

    This is tested and works fine on the following table structure.


    CREATE TABLE IF NOT EXISTS `messages` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `user_id` int(11) NOT NULL,
      `message` text NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
    
    INSERT INTO `messages` (`id`, `user_id`, `message`) VALUES
    (1, 1, 'test'),
    (2, 1, 'test 2'),
    (3, 2, 'test 3');
    
    CREATE TABLE IF NOT EXISTS `relationships` (
      `leader` int(11) NOT NULL,
      `follower` int(11) NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    INSERT INTO `relationships` (`leader`, `follower`) VALUES
    (1, 2);
    
    CREATE TABLE IF NOT EXISTS `users` (
      `user_id` int(11) NOT NULL AUTO_INCREMENT,
      `username` varchar(255) NOT NULL,
      PRIMARY KEY (`user_id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
    
    INSERT INTO `users` (`user_id`, `username`) VALUES
    (1, 'solomon'),
    (2, 'muna');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i have database like this Users Table user_id | username | branch_id(foreignkey)| Approved_id(foreignkey)
I have a USERS table like this USERS user_id | username 1 tom 2
I have 4 tables. Table A that has users - ( user_id, username, and
I have this table: User id INT PK login VARCHAR UNIQUE I want to
My MySQL tables structure (3 table) users id username images id user_id image user_follow
My database have got 4 table : users id username images id user_id image
Users Table user_id username thumb_id fullimage_id 1 jprescott 14 15 2 lpausch 18 19
I have two tables. The first is user ; this consists of username and
I have database structure as User Table(user id, username, first name,last name) Event Table(event
For example: Table 1 : user_ID - username - first_name - email - Table

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.