Skip to content

Instantly share code, notes, and snippets.

@krisives
Created January 31, 2013 17:37
Show Gist options
  • Save krisives/4684659 to your computer and use it in GitHub Desktop.
Save krisives/4684659 to your computer and use it in GitHub Desktop.
SELECT
(
SELECT COUNT(*)
FROM `VendorRequests`
LEFT JOIN (
SELECT *
FROM (
SELECT *
FROM `MfgUpdates` AS `UpdatesOrdered`
ORDER BY `UpdatesOrdered`.`When` DESC
) `GroupingUpdates`
GROUP BY `GroupingUpdates`.`Mfg`, `GroupingUpdates`.`Option`
) AS `LastUpdate` ON (
`VendorRequests`.`Vendor`=`LastUpdate`.`Mfg` AND
`VendorRequests`.`Option`=`LastUpdate`.`Option`
)
WHERE
`Vendor`=`ID` AND
IFNULL(`VendorRequests`.`When` > `LastUpdate`.`When`, true)
) AS `requests`,
`mfg`.*
FROM `mfg`
$where
ORDER BY $sorter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment