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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:08:39+00:00 2026-05-16T00:08:39+00:00

I have these information : Table Users => **Id** **Name** 1 a 2 b

  • 0

I have these information :
Table “Users” =>

 **Id**     **Name** 
   1           a
   2           b
   3           c
   4           d
   5           e

Table “Friends” =>

**SenderId**  **ReceiverId**    **State**
     1              2              x 
     2              3              ok 
     3              1              ok
     3              4              ok
     5              3              ok 
     5              4              ok

Table “Events” =>

     **SenderId**    **receiverId**     **text**
 1        1                3              ssss
 2        3                1             dsadsa
 3        2                3             safsdf
 4        3                5              fgfdgfd
 5        4                3             fgfhgfh
 6        5                4              sad sad

My question is that how could I get the events of user’s friends in one sql statement using JOINS only .

for example :=>

  • userId : 1
  • his friends : 3 (state = ok)
  • friends events : 1, 2, 3, 4, 5 (events from 1 to 5 have the userId 3 which considered as a friend to user 1 )

ANY HELP .. THANKS 😉 !!

  • 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-16T00:08:39+00:00Added an answer on May 16, 2026 at 12:08 am

    You didn’t specify a name for the first column in your Events table so I’ve called it row_ID:

    SELECT U1.ID AS user_ID, U1.Name AS user_name, 
           U2.ID AS friend_user_ID, U2.Name AS friend_user_name, 
           E1.row_ID, E1.text AS event_text
      FROM Users AS U1
           INNER JOIN Friends AS F1
              ON (
                  U1.ID = F1.ReceiverId
                  OR U1.ID = F1.SenderId
                 )
                 AND F1.State = 'ok'
           INNER JOIN Users AS U2
              ON U2.ID = F1.SenderId
           INNER JOIN Events AS E1
              ON (
                  U2.ID = E1.ReceiverId
                  OR U2.ID = E1.senderId
                 )
     WHERE U1.ID = 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these 3 tables: users table(PK user_id) Fields: user_id, user_first_name, user_last_name, username, user_email...etc
Given that I have a table that holds vehicle information and one of those
I have these roles:Admin, Doctor and Patient. But login information is stored in different
I have two lists: ask[] timeStamp[] I need to add the information in these
I have an text outline tree where i display a lot of information There
I have a rich text box that is being updated with log information. There
I have a basic users table I want to create in MySQL. I do
I have a field called PropertyValue in the UserProfile table that can contain information
I have a users table in a database, where the user enters a form
I have the following tables in MySQL: users profile rates In the users 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.