Skip to content

Instantly share code, notes, and snippets.

@drale2k
Created January 23, 2012 07:26
Show Gist options
  • Save drale2k/1661381 to your computer and use it in GitHub Desktop.
Save drale2k/1661381 to your computer and use it in GitHub Desktop.
Selecting all locations
SELECT L.id, L.name, L.description, L.created_at,
GROUP_CONCAT(
DISTINCT CONCAT(C.lat, ":", C.lng)
ORDER BY C.coordinate_order ASC SEPARATOR ", "
) AS coordinates,
GROUP_CONCAT(
DISTINCT CONCAT(M.media_type, "#", M.media_url)
) AS media
FROM locations AS L
INNER JOIN locations_coordinates AS C ON L.id = C.location_id
INNER JOIN locations_media AS M ON L.id = M.location_id
WHERE L.id = C.location_id
GROUP BY L.id, L.name, L.description, L.created_at ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment