Skip to content

Instantly share code, notes, and snippets.

@objectivehtml
Created March 3, 2014 23:09
Show Gist options
  • Select an option

  • Save objectivehtml/9336582 to your computer and use it in GitHub Desktop.

Select an option

Save objectivehtml/9336582 to your computer and use it in GitHub Desktop.
(SELECT exp_channel_titles.entry_id, COUNT(exp_categories.cat_id) AS cat_count, exp_categories.cat_id, exp_categories.cat_id as \'category_id\', GROUP_CONCAT(cat_id SEPARATOR \'|\') as \'cat_ids\', GROUP_CONCAT(cat_id SEPARATOR \'|\') as \'category_ids\', exp_categories.cat_name, exp_categories.cat_name as \'category_name\', exp_categories.cat_url_title, exp_categories.cat_url_title as \'category_url_title\', exp_categories.parent_id as \'cat_parent_id\', exp_categories.parent_id as \'category_parent_id\', exp_categories.site_id as \'cat_site_id\', exp_categories.site_id as \'category_site_id\', exp_categories.group_id as \'cat_group_id\', exp_categories.group_id as \'category_group_id\', exp_categories.cat_description as \'cat_description\', exp_categories.cat_description as \'category_description\', exp_categories.cat_image as \'cat_image\', exp_categories.cat_image as \'category_image\', GROUP_CONCAT(exp_categories.cat_name SEPARATOR \'|\') as \'cat_names\', GROUP_CONCAT(exp_categories.cat_name SEPARATOR \'|\') as \'category_names\', GROUP_CONCAT(exp_categories.cat_url_title SEPARATOR \'|\') as \'cat_url_titles\', GROUP_CONCAT(exp_categories.cat_url_title SEPARATOR \'|\') as \'category_url_titles\', GROUP_CONCAT(exp_categories.parent_id SEPARATOR \'|\') as \'cat_parent_ids\', GROUP_CONCAT(exp_categories.parent_id SEPARATOR \'|\') as \'category_parent_ids\', GROUP_CONCAT(exp_categories.cat_description SEPARATOR \'|\') as \'cat_descriptions\', GROUP_CONCAT(exp_categories.cat_description SEPARATOR \'|\') as \'category_descriptions\', GROUP_CONCAT(exp_categories.group_id SEPARATOR \'|\') as \'cat_group_ids\', GROUP_CONCAT(exp_categories.group_id SEPARATOR \'|\') as \'category_group_ids\', GROUP_CONCAT(exp_categories.site_id SEPARATOR \'|\') as \'cat_site_ids\', GROUP_CONCAT(exp_categories.site_id SEPARATOR \'|\') as \'category_site_ids\', GROUP_CONCAT(exp_categories.cat_image SEPARATOR \'|\') as \'cat_images\', GROUP_CONCAT(exp_categories.cat_image SEPARATOR \'|\') as \'category_images\'
FROM exp_channel_titles
LEFT JOIN exp_category_posts USING (entry_id)
LEFT JOIN exp_categories USING (cat_id)
WHERE ('.$required_where.') '.(count($cat_where) > 0 ? ' AND ('. implode(' '.$clause.' ', $cat_where) .')' : NULL).'
GROUP BY entry_id
'.(count($cat_having) > 0 ? 'HAVING cat_count '.$count_op.' '.count($cat_having) : NULL).'
) cc
INNER JOIN
exp_channel_data ON exp_channel_data.entry_id = cc.entry_id'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment