Answer the question
In order to leave comments, you need to log in
How to deal with NULL fields after JOIN with GROUP BY in MySQL?
Greetings!
Please tell me how to get the right results. There are signs:
For convenience, uploaded to the sandbox sqlfiddle.com/#!9/1e9b8c/19
CREATE TABLE sour
(`id` int, `source` varchar(7), `description` varchar(55))
;
INSERT INTO sour
(`id`, `source`, `description`)
VALUES
(1, 'raz', 'aza1'),
(2, 'dva', 'aza2'),
(3, 'tri', 'aza3'),
(4, 'chetire', 'aza4')
;
CREATE TABLE app
(`id` int, `sour_id` int, `name` varchar(55))
;
INSERT INTO app
(`id`, `sour_id`, `name`)
VALUES
(1, 1, 'zzz1'),
(2, 3, 'zzz2'),
(3, 3, 'zzz3'),
(4, 1, 'zzz4'),
(5, 3, 'zzz5'),
(6, 4, 'zzz6')
;
SELECT
sour.source,
COUNT(app.sour_id) as `c`
FROM `app`
RIGHT JOIN `sour` ON sour.id = app.sour_id
WHERE app.id > 2
GROUP BY(app.sour_id);
raz 1
tri 2
chetire 1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question