Answer the question
In order to leave comments, you need to log in
Why doesn't mysql query output a record where the number of matches is 0?
Hello! There is a query that should display the services and the number of subscriptions to these services within a certain number.
This line WHERE service.id in (13,74,71,72)
contains a list of services that need to be checked, and I know for sure that the subscriber is not subscribed to the service 74
Here is my request
SELECT service.id as service_id, count(subs.id) as c
FROM Subscriptions subs
INNER JOIN Services service ON subs.service_id = service.id
WHERE service.id in (13,74,71,72)
AND subs.msisdn=992777757031
GROUP BY service.id
ORDER BY c DESC;
Answer the question
In order to leave comments, you need to log in
The list of required ids must be the source of the request data, and the base one. And in the event of the possible absence of related records, the binding should be external.
SELECT service.id AS service_id, COUNT(subs.id) AS c
FROM ( SELECT 13 id UNION
SELECT 74 UNION
SELECT 71 UNION
SELECT 72 ) AS service
LEFT JOIN Subscriptions subs ON subs.service_id = service.id AND subs.msisdn=992777757031
GROUP BY service.id
ORDER BY c DESC;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question