Skip to content

Instantly share code, notes, and snippets.

@shofetim
Created October 20, 2011 19:13
Show Gist options
  • Select an option

  • Save shofetim/1302018 to your computer and use it in GitHub Desktop.

Select an option

Save shofetim/1302018 to your computer and use it in GitHub Desktop.
SELECT COUNT(*) AS `count`
FROM `forms` AS `Form`
LEFT JOIN forms_tags AS `FormsTags` ON (`Form`.`id` = `FormsTags`.`form_id`)
LEFT JOIN tags AS `Tag` ON (`FormsTags`.`tag_id` = `Tag`.`id`)
LEFT JOIN `statuses` AS `Status` ON (`Form`.`status_id` = `Status`.`id`)
LEFT JOIN `form_types` AS `FormType` ON (`Form`.`form_type_id` = `FormType`.`id`)
LEFT JOIN `summaries` AS `Summary` ON (`Form`.`summary_id` = `Summary`.`id`)
WHERE ((`Form`.`title` LIKE '%titl%') OR (`Tag`.`title` LIKE '%titl%'))
GROUP BY `Form`.`id` ;
//Result
+-------+
| count |
+-------+
| 1 |
| 2 |
| 2 |
+-------+
//Desired Result
+-------+
| count |
+-------+
| 3 |
+-------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment