Im joining two tables together, and i want to list only those rows, which groupped rows count not matching table A's pieces value.
table A
id name pieces
1 name_1 6
2 name_2 2
table B
a_id
1
1
2
2
So what i want is to fetch all the a.name where a.piece<>the groupped rows count.
something like this:
SELECT a.name
FROM a
INNER JOIN b
ON a.id = b.a_id
WHERE a.pieces <> Count(*)
GROUP BY id
this results an invalid use of group function
also tried this:
SELECT a.name,
Count(*) AS count
FROM a
INNER JOIN b
ON a.id = b.a_id
WHERE a.pieces <> count
GROUP BY id
error: unknown column 'count'
In this case, as result, i only want to receive 1 row like this:
name count
name_1 2
Because name_1
has 2 grouped rows from table.b
and it is not matching a.piece
which is 6.