I have two tables in MYSQL:
account:
id apelido_usuario
1 caio
2 manoel
3 josé
product
idconta status
1 3
1 3
1 1
2 3
3 2
I made a SELECT like this:
SELECT * FROM conta
WHERE apelido_usuario <> ''
AND conta.id IN (SELECT produto.idconta FROM produto WHERE produto.status = '3');
It worked as it wanted, it only lists the users that have product registered and that the status of this product equals 3.
Now I need an ORDER BY, which is ordered by the user who has more products with the status = '3' in the front, how to do it?
I tried something like this:
SELECT * FROM conta
WHERE apelido_usuario <> ''
AND conta.id IN (SELECT produto.idconta FROM produto WHERE produto.status = '3')
ORDER BY SUM(conta.id IN (SELECT produto.idconta FROM produto WHERE produto.status = '3')) DESC;
But I realized that it is not the right ...