Skip to content

Instantly share code, notes, and snippets.

@rafl
Created April 12, 2013 14:38
Show Gist options
  • Save rafl/5372485 to your computer and use it in GitHub Desktop.
Save rafl/5372485 to your computer and use it in GitHub Desktop.
WITH notes AS (
SELECT n.note_id, n.created_by, n.note_content, n.revision_number, t.tag
FROM gphat.marker_notes AS n
LEFT OUTER JOIN gphat.marker_note_tags AS t
ON t.note_id = n.note_id AND t.created_by = n.created_by
WHERE n.marker_id = ? AND n.created_by = ?
), photos AS (
SELECT p.photo_id, p.created_by, mimetype(p.image_content) as mime_type,
p.revision_number, t.tag
FROM gphat.marker_photos AS p
LEFT OUTER JOIN gphat.marker_photo_tags AS t
ON t.photo_id = p.photo_id AND t.created_by = p.created_by
WHERE p.marker_id = ? AND p.created_by = ?
)
SELECT n.note_id, n.created_by, n.note_content, n.revision_number, n.tag,
p.photo_id, p.created_by, p.mime_type, p.revision_number, p.tag
FROM notes AS n
FULL OUTER JOIN photos AS p ON false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment