CREATE TABLE tablea (
id char(25) NULL,
qid int(11) NULL
)
GO
INSERT INTO tablea(id, qid)
VALUES('A', 3),('B', 3),('C', 3),('D', 3)
GO
CREATE TABLE tableb (
pk int(11) NOT NULL,
qid varchar(25) NULL,
cnt varchar(25) NULL
)
GO
INSERT INTO tableb(pk, qid, cnt)
VALUES(0, '3', 'A'),(1, '3', 'D'),(2, '3', 'A'),(3, '3', 'C'),(4, '3', 'A'),(5, '3', 'D'),(6, '3', 'A'),(7, '3', 'A'),
GO
By counting TableB, Total Cnt as per TableA’s ID is: A=5, B=0, C=1, D=2. When select count(Cnt) group by ID, the result does not include B, i.e. result: A=5,C=1,D=2.
How can I include B=0 using mySQL.
I think what you’re trying to achieve is;
Which will count in TableB the occurrences of all ID’s in TableA even if they don’t exist in TableB.
(side note, your naming is a bit hard to figure out)