The example keeps every service and matches only staging runs. The environment condition belongs in ON. Moving it into WHERE filters the finished result and removes the services without a matching run.
SELECT s.name, d.id AS run_id
FROM services AS s
LEFT JOIN deployments AS d ON s.id = d.service_id
AND d.environment = 'staging';Build the same report for production. Show each service’s name and the deployment ID as run_id. Keep every production run and include one row with a NULL run ID for each service without a production run.