Posted By

lastobelus on 03/24/11


Tagged

join Subquery usergateways


Versions (?)

users with more than one of a gateway


 / Published in: SQL
 

  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  

You need to login to post a comment.