0

Say I have a many to many relationship and when I query the db for the left table using a join from the right table I get duplicates because of this many to many relationship. I can use group by on the primary key to get rid of these in mysql or distinct.

However I've been told that distinct & group by are not good re:performance. With that said, I would also assume mysql performance would be better than javascript performance.

Should I be filtering my results in javascript or use group by in mysql? Any reason why one would be faster than the other?

1
  • As pointed by @Rushed this largery depends on the scenario you are facing. Generally speaking when i face many-to-many relations i always try to implement a third table of relations in order to avoid complications with distinct/group by... Commented Oct 26, 2017 at 20:46

1 Answer 1

1

it depends on how much data and how many concurrent users:

  • if the data is reasonably low and not much concurrent users then mysql group by/distinct is the best solution.
  • if the data is reasonably low and high concurrent users then Javascript filtering is the best solution here.
  • if the data is large regardless of how many concurrent users then you should look for another solution than just group by/distinct and I'm not talking about filtering in javascript because in this case the huge data will cause low performance in user's browser.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.