Created
May 28, 2012 06:27
-
-
Save zephiransas/2817686 to your computer and use it in GitHub Desktop.
This file contains 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 * FROM shops WHERE | |
( | |
SELECT management_division_value | |
FROM shop_management_divisions | |
WHERE management_division_id = 7 AND shop_management_divisions.shop_id = shops.id | |
) = 1 AND | |
( | |
SELECT management_division_value | |
FROM shop_management_divisions | |
WHERE management_division_id = 8 AND shop_management_divisions.shop_id = shops.id | |
) = 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a = ShopManagementDivision.where(:management_division_id => 7,:management_division_value => 1)
b = ShopManagementDivision.where(:management_division_id => 8,:management_division_value => 4)
shops = Shop.where(:id => a.map{|v| v.shop_id}).where(:id => b.map{|v| v.shop_id})