You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
393 B

  1. SELECT
  2. user_id,
  3. ip,
  4. max(used_at) AS used_at
  5. FROM (
  6. SELECT
  7. id AS user_id,
  8. sign_up_ip AS ip,
  9. created_at AS used_at
  10. FROM users
  11. WHERE sign_up_ip IS NOT NULL
  12. UNION ALL
  13. SELECT
  14. user_id,
  15. ip,
  16. updated_at
  17. FROM session_activations
  18. UNION ALL
  19. SELECT
  20. user_id,
  21. ip,
  22. created_at
  23. FROM login_activities
  24. WHERE success = 't'
  25. ) AS t0
  26. GROUP BY user_id, ip