SELECT A.a, ( SELECT COUNT(1) FROM (SELECT B.b FROM B WHERE B.b = A.a LIMIT 12) ) AS somename FROM A WHERE cond;
SELECT A.a, if (X.cnt >= 12, 12 , X.cnt) as somename
FROM A
INNER JOIN (SELECT B.b, count(*) as cnt FROM B GROUP BY B.b) as X
ON A.a = X.b
WHERE cond