Answer the question
In order to leave comments, you need to log in
How to create nested queries so that the data from the outer one is used in the inner one?
The subject is strange, sorry.
I hope this request example is not so scary and clear.
SELECT a, ( SELECT COUNT(1) FROM (SELECT Bb FROM B WHERE Bb = a LIMIT 12) ) AS somename FROM A WHERE cond;
Answer the question
In order to leave comments, you need to log in
3 levels of nesting, in my opinion - a firing squad. Better deal with JOIN. I would be happy to help, but there is no desire to understand this spherical horse in a vacuum.
UPD: Is that not possible?
SELECT a,Count(a) FROM A
INNER JOIN B ON B.b = A.a
WHERE ...
GROUP BY a
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question