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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:05:48+00:00 2026-05-13T13:05:48+00:00

Users send messages to each others message boxes, how to find the user who

  • 0

Users send messages to each others message boxes, how to find the user who knows the most other users (receive AND send??). I have SQL Server.

Table:

  • USER_ID
  • USER_NAME
  • USER_GROUP
  • MESSAGE_ID
  • MESSAGE_MESSAGE
  • MESSAGE_FROM_USER
  • M_ESSAGE_TO_USER

A user can send and receive, so who knows the most other users (by send AND receive??)

  • 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-13T13:05:48+00:00Added an answer on May 13, 2026 at 1:05 pm

    SQL Server 2005+, Using CTE:


     WITH usr_list AS (
       SELECT x.user_id,
              x.message_from_user AS other_user
         FROM TABLE x
       UNION
       SELECT y.user_id,
              y.message_to_user AS other_user
         FROM TABLE y)
      SELECT TOP 1
             ul.user_id,
             COUNT(*) AS num_friends
        FROM usr_list ul
    GROUP BY ul.user_id
    ORDER BY num_friends DESC
    

    Non CTE equivalent:


      SELECT TOP 1
             ul.user_id,
             COUNT(*) AS num_friends
        FROM (SELECT x.user_id,
                     x.message_from_user AS other_user
                FROM TABLE x
              UNION
              SELECT y.user_id,
                     y.message_to_user AS other_user
                FROM TABLE y) ul
    GROUP BY ul.user_id
    ORDER BY num_friends DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have models User and Message. Every user can send messages to other users.
I want to be able to have individual users send messages to each other
I have make a messaging system in which user can send messages to each
I have a database of users where they can send messages to other users
I am developing a system, where each user can send personal messages to other
Using the privatemessage module, users can send messages to each other as in facebook.
I have an app where users can send emails to other users by selecting
I have the following scenario: Users send email messages to the special mail addresses
I dont want code, that users send each other to run on my server.
I need to send a Push notification message to all users of my app.

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.