users with more than one of a gateway


/ Published in: SQL
Save to your folder(s)



Copy this code and paste it in your HTML
  1. SELECT
  2. users.id, users.sage_username, users.email,
  3. organizations.id, organizations.name,
  4. user_gateways.gateway_name, user_gateways.merchant_id, user_gateways.merchant_key, user_gateways.login, user_gateways.email, user_gateways.active, user_gateways.type
  5. FROM organizations
  6. JOIN users ON organizations.created_by_id = users.id
  7. JOIN user_gateways ON user_gateways.organization_id=organizations.id
  8. JOIN
  9. (SELECT organization_id, gateway_name, COUNT(gateway_name)
  10. FROM user_gateways
  11. GROUP BY organization_id, gateway_name
  12. HAVING COUNT(gateway_name) > 1) AS them
  13. ON them.organization_id = organizations.id;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.