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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:31:31+00:00 2026-05-16T06:31:31+00:00

I have 2 tables, ‘interests’ and ‘users_interests’. ‘users_interests’ just has userid and interestid fields.

  • 0

I have 2 tables, ‘interests’ and ‘users_interests’.

‘users_interests’ just has userid and interestid fields.
‘interests just has an id and a name.

I simply need to find userid’s who have more than 3 interest ID’s in common. I have been told that a Self Join is involved, but I cannot seem to get this to work.

Someone said something like this could work:

SELECT 
      others.userid 
  FROM interests AS user 
  JOIN interests AS others 
      USING(interestid) 
  WHERE user.userid = 2 
  GROUP BY 
      others.userid 
  ORDER BY COUNT(*) DESC

But I’m having no luck with it.

  • 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-16T06:31:32+00:00Added an answer on May 16, 2026 at 6:31 am
    SELECT ui.userid, COUNT(*) AS common_interests
    FROM users_interests ui
    WHERE ui.interestid IN (
        SELECT ui2.interestid FROM users_interests ui2 WHERE ui2.userid = 2
    ) 
    AND ui.userid <> 2
    GROUP BY ui.userid
    HAVING common_interests > 3;
    

    Note the occurence of the userid we’re basing our search on (2) on two places in the code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tables: users with the fields id, premium votes with the fields userid,
I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int
I have tables Product ( ID, CategoryID, ... ) Category ( ID, Name, ..
hi i have tables like this: Persons: person_id, name then i have many langauge
I have tables like: 'profile_values' userID | fid | value -------+---------+------- 1 | 3
I have tables: users {id, name} projects {id, name} roles {id, name} projects_users {id,
I have tables like tbl_biodata: id : int value=>1 name : varchar(50) value =>
I have tables item and store (it's a store management system). item table has
I have tables contracts and users and i need to show contracts sorted by
Say I have tables Parts PartID (Primary Key) Part Name Orders OrderID (Primary Key)

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.