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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:36:35+00:00 2026-06-02T12:36:35+00:00

I have a table in SQL Server to record the IP of all the

  • 0

I have a table in SQL Server to record the IP of all the members’ login of my website.

    ID   MEMBER      IP       
    ---------------------------------------
    1    member1     1.1.1.1
    2    member2     2.2.2.2
    3    member3     1.1.1.1
    4    member3     3.3.3.3
    5    member4     3.3.3.3

I want to figure out a way to search for associated member and their associated IP.

First example,

  • member1 logged in from 1.1.1.1 before
  • member3 logged in from 1.1.1.1 and 3.3.3.3 before
  • member4 logged in from 3.3.3.3 before

So, For member1:

  • Associated members: member1, member3, member4
  • Associated IPs : 1.1.1.1, 3.3.3.3

For member2, associated member is member2 and associated IP is 2.2.2.2 .

This association system is to help manage fake players and the number of members is big ( ~100k ). So loading time is a big issue.

My question:

  • Is there a SQL Query to generate the list of associated members and associated IPs?

=======Table to test======

CREATE TABLE [dbo].[tblAssociation](
    [ID] [int] NULL,
    [Member] [nvarchar](50) NULL,
    [IP] [nvarchar](50) NULL
) ON [PRIMARY]

GO

INSERT INTO [tblAssociation] VALUES(1,'member1','1.1.1.1')
INSERT INTO [tblAssociation] VALUES(2,'member2','2.2.2.2')
INSERT INTO [tblAssociation] VALUES(3,'member3','1.1.1.1')
INSERT INTO [tblAssociation] VALUES(4,'member3','3.3.3.3')
INSERT INTO [tblAssociation] VALUES(5,'member4','3.3.3.3')

======shankar’s suggestion====

SELECT T1.Member, T1.IP, T2.Member 
FROM   tblAssociation T1 
INNER JOIN tblAssociation T2 ON T1.IP = T2.IP
AND T1.Member = 'member1'

if you try, I can only get associated member = member1, member3.

member4 is not there, but he should be associated because member4 and member3 connected to 3.3.3.3 before

  • 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-02T12:36:37+00:00Added an answer on June 2, 2026 at 12:36 pm

    Building on the same statement as shankar_pratap, following CTE would get you all related members to a given member. The real difficulty here is in knowing when to stop the recursion. For the recursion to stop, both q.ID <> a.ID and q.OriginalID <> r.ID are required.

    SQL Statement

    ;WITH q AS (
      SELECT  OriginalID = r.ID
              , r.ID
              , r.Member
              , r.IP
      FROM    tblAssociation a
              INNER JOIN tblAssociation r ON r.IP = a.IP
      WHERE   a.Member = 'member1'
      UNION ALL
      SELECT  q.OriginalID
              , r.ID
              , r.Member
              , r.IP
      FROM    tblAssociation a
              INNER JOIN tblAssociation r ON r.IP = a.IP
              INNER JOIN q ON q.Member = a.Member AND q.ID <> a.ID
      WHERE   q.OriginalID <> r.ID
    )
    SELECT  DISTINCT ID
            , Member
            , IP
    FROM    q
    

    Result

    ID  Member  IP
    1   member1 1.1.1.1
    3   member3 1.1.1.1
    4   member3 3.3.3.3
    5   member4 3.3.3.3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ADOQuery that inserts a record to SQL Server 2005 table that
I have a table in SQL Server, where i want inserts to be added
I have an audit table in SQL server. It is to record an entry
I have a SQL Server database with 500,000 records in table main . There
I have a table in SQL Server but there is no column to show
I have a table in SQL server that has the normal tree structure of
I have a table in SQL Server 2005 which has three columns: id (int),
I have a table in SQL Server 2000 Standard Edition called dbo.T668 (don't blame
I have a table in SQL Server 2005 which has a date time field.
I have a table in SQL server: Categories -------------- CategoryID (uniqueidentifier) ParentCategoryID (uniqueidentifier) allow

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.