Skip to content

Instantly share code, notes, and snippets.

@AndrewRayCode
Created October 11, 2016 03:50
Show Gist options
  • Save AndrewRayCode/b3a807654f3835e25ea7213c29adee8e to your computer and use it in GitHub Desktop.
Save AndrewRayCode/b3a807654f3835e25ea7213c29adee8e to your computer and use it in GitHub Desktop.
SELECT "posts".*,
Group_concat(tags.id, "↕") AS keyword_ids,
Group_concat(tags.NAME, "↕") AS keyword_names,
Group_concat(Ifnull(tags.description, "null"), "↕") AS keyword_descriptions,
FROM "posts"
LEFT JOIN "post_tags"
ON "post_tags"."post_id" = "posts"."id"
LEFT JOIN "tags"
ON "post_tags"."keyword_id" = "tags"."id"
WHERE "tags"."name" IN ( 'sometag' )
GROUP BY "posts"."id"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment