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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:31:58+00:00 2026-06-16T00:31:58+00:00

Excuse me if this has been asked before, but I tried looking for something

  • 0

Excuse me if this has been asked before, but I tried looking for something similar but couldn’t find anything.

I have three tables: users, hobbies and user_hobbies (linking the first two). I want to calculate the similarity betweet two users based on their hobbies. For this, I need, first of all, two sets: User A hobbies and user B hobbies, which I can acquire with two simple queries. I have to calculate these two sets for other reasons too, in a php file, so they are available to me, in two arrays, for the next step:

I have to calculate their common hobbies (i.e. the intersection of the sets).

Idea #1: Having two arrays, I can calculate through some method the common elements.

Idea #2: I can make a third query (e.g. SELECT hobby FROM user_hobbies WHERE user_id IN ('uid_A', 'uid_B') GROUP BY hobby HAVING COUNT (*) = 2) and not bother myself.

I suppose my question is about performance. Is it quicker to calculate manually or are mysql queries much faster?

  • 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-16T00:31:59+00:00Added an answer on June 16, 2026 at 12:31 am

    You already have a normalized table to hold the user-hobbies table, so why not go with that?

    Generally speaking, SQL will be much faster, at least for the first 100k records or so. Then you’ll see a performance drop on queries that vet through columns that aren’t indexed, or from queries that use the ‘filesort’ to order large datasets brought on by the ORDER BY keyword.

    For scalability, I recommend using an inner join to narrow down the possibilities for starters.

    Think critically about this. Are there any other columns not mentioned could indicate that the user could have more than one hobby? These are the things you consider when looking to scale your application.

    Otherwise, you should be fine for starters, lest you should be optimizing prematurely.

    I would go with Option #2.

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

Sidebar

Related Questions

Excuse me if this has indeed been asked before, I couldn't see anything that
Excuse me if this is a question that has been asked before, if so
Excuse me if this has already been asked, but searching for coalesce brings up
I could imagine this question has already been asked, but I actually could not
I feel like this question has already been asked and answered, yet I couldn't
This question has been brought up before, and I have searched many of the
This has been asked before, and will be asked again! I am currently building
Excuse the n00bness of this question, but I have a web application where I
Excuse me if this is the wrong place to ask. I have been using
Please excuse the simplicity and length of this, but I have a little test

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.