Skip to content

Instantly share code, notes, and snippets.

@prgTW
Last active July 9, 2020 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prgTW/1908657ce77e859b79a7fd4b76da6c43 to your computer and use it in GitHub Desktop.
Save prgTW/1908657ce77e859b79a7fd4b76da6c43 to your computer and use it in GitHub Desktop.
SELECT 1
FROM `agreement`
LEFT JOIN `product1` ON (
`agreement`.`id`=`product1`.`agreement_id`
AND `product1`.`status` IN ('active', 'expiring')
)
LEFT JOIN `product2` ON (
`agreement`.`id`=`product2`.`agreement_id`
AND `product2`.`status` IN ('active', 'expiring')
)
WHERE `agreement`.customer_id = :id
GROUP BY agreement.id
HAVING count(product1.id) > 0 OR count(product2.id) > 0
LIMIT 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment