Reputation: 447
I have two MySQL queries that return the same result. I would like to know which one is the best or the optimized solution? I am aware of MySQL profiling, I only concern about Having alternatives?
SELECT *
FROM users
WHERE id IN (
SELECT user_id
FROM users_courses
GROUP BY user_id
HAVING COUNT(*) >= 2
)
OR
SELECT coding_test.users.name
FROM coding_test.users_courses
INNER JOIN coding_test.users ON coding_test.users.id = coding_test.users_courses.user_id
GROUP BY coding_test.users.name
HAVING COUNT(coding_test.users_courses.course_id) >= 2
Thank you
Upvotes: 0
Views: 274
Reputation: 2197
I was searching about MySQL benchmarking, as it was a doubt of my own too, and found another very interesting answer that can help you with even more complex queries:
Testing performance of queries in mysql
Hope it helps!
Upvotes: 1