I've seen in the post called something like "a small change you've done that has increased the performance of your application" a comment about changing from:
SELECT U.userid,groups_in=(
SELECT COUNT(*)
FROM usersgroup
WHERE userid=U.userid)
FROM tbl_users U
to:
SELECT U.userid, groups_in
FROM users U
LEFT JOIN (
select userid, groups_in=count(*)
from usersgroup
group by userid) GROUPS
ON GROUPS.userid = U.userid
And I thought "oh, that's the kind of thing I've been doing wrong!!", however I tried both queries in the same environment and both gives me the same execution time and the db execution plan looks exactly the same.
Is there a better way to do the same operation? are those queries both absolutely fine?