Last active
December 30, 2015 10:19
-
-
Save RealNobody/7815078 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
merchant_locations.address_id | |
, merchant_locations.merchant_id | |
, deals.* | |
, merchants.* | |
, addresses.* | |
FROM | |
merchant_locations | |
INNER JOIN | |
( | |
SELECT | |
merchant_locations.address_id AS address_id | |
FROM | |
merchant_locations | |
GROUP BY | |
merchant_locations.address_id | |
HAVING | |
COUNT(DISTINCT merchant_locations.merchant_id) > 1 | |
) AS bad_addresss | |
ON (bad_addresss.address_id = merchant_locations.address_id) | |
INNER JOIN deals | |
ON (deals.merchant_id = merchant_locations.merchant_id) | |
INNER JOIN addresses | |
ON (addresses.id = merchant_locations.address_id) | |
INNER JOIN merchants | |
ON (merchants.id = merchant_locations.merchant_id) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment