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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:17:20+00:00 2026-06-08T12:17:20+00:00

i have 2 tables: table1 id message user 1 testing 23 2 testing again

  • 0

i have 2 tables:

table1

id message       user
1  testing       23
2  testing again 44
3  test..        23
5  lol           12
6  test..        6

and

table2

id user friend
1  23   44
2  23   6
3  19   12
4  23   32
5  23   76
6  23   89

i am trying to get the messages of all users that are friends with 23 including 23

like:

id message       user   id user friend
1  testing       23     n  n    n
2  testing again 44     1  23   44
3  test..        23     n  n    n
6  test..        6      2  23   6

we can see that 12 is missing because he is not friend with 23 but only with 19

i’ve got this

SELECT * 
FROM table1 AS w
INNER JOIN table1 AS f ON w.user = f.friend 
WHERE (w.user = 23) 

but in case 23 has messages but no friends it will return null and also this will return other friends of 23 like 76 and 89 that have no messages..

🙂 confused?

any ideas?

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-06-08T12:17:21+00:00Added an answer on June 8, 2026 at 12:17 pm

    Try this:

    SELECT 
        table1.*, 
        table2.* 
    FROM 
        table2 
            RIGHT JOIN table2 
            ON table2.friend = table1.user 
    WEHRE 
        table2.user = 23
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: User , table1 and table2 . User has_many table1 .
I have Messages and User models with corresponding tables. The Messages table has such
I have three tables: User: UserId (pk) FirstName Lastname Messages: MessageId (pk) Heading Body
I have a following problem. I have three tables: message, comment and user. I
I have 3 tables MySQL (MyIsam): user (id), message (id, userId, ...), archivedMessage (id,
I have 3 tables; Inbox, Outbox, and Messages. For a single message, the data
I have 3 Tables: Messages, Users, and Friends. Messages: msg_id, uid_fk, message, alert, created,
I have a Message table and a User table. Both are in separate databases.
I have table messages | id | user_id | recepient_id | message | 1
I have a user and a message table. User to Message are one-to-many relationships

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.