Skip to content

Instantly share code, notes, and snippets.

@martintsch
Created November 11, 2015 10:39
Show Gist options
  • Select an option

  • Save martintsch/d928ccdfe10e65972693 to your computer and use it in GitHub Desktop.

Select an option

Save martintsch/d928ccdfe10e65972693 to your computer and use it in GitHub Desktop.
locations by vehicle id
SELECT * FROM locations l INNER JOIN (SELECT u.first_name, u.last_name, u.id as user_id, t1.id as vehicle_id, t1.regno FROM users u INNER JOIN (SELECT * FROM vehicles v WHERE sak_activated_at IS NOT NULL AND sak_deactivated_at IS NULL) t1 ON t1.user_id = u.id) t2 ON l.vehicle_id = t2.vehicle_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment