SELECT a.*,B.num
FROM tb1 AS A
    LEFT JOIN (SELECT userid,COUNT(*) AS num FROM tb2 GROUP BY userid) AS B
ON A.id=B.userid