Created
April 10, 2012 06:09
-
-
Save jdunck/2348676 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 DISTINCT (contacts_itemcandidate.id is not null) AS `social_like`, (contacts_itemdistrict.id is not null) AS `in_district`, (contacts_item.api_voter_id > 0) AS `is_voter`, `contacts_item`.`id` | |
FROM `contacts_item` | |
INNER JOIN | |
`contacts_itemuser` | |
ON | |
(`contacts_item`.`id` = `contacts_itemuser`.`item_id`) | |
LEFT OUTER JOIN | |
`contacts_itemcandidate` | |
ON | |
(`contacts_item`.`id` = `contacts_itemcandidate`.`item_id`) | |
LEFT OUTER JOIN | |
`contacts_itemdistrict` | |
ON | |
(`contacts_item`.`id` = `contacts_itemdistrict`.`item_id`) | |
WHERE | |
`contacts_item`.`account_type` IN ('facebook', 'googleplus', 'linkedin', 'twitter', 'email') | |
AND | |
(`contacts_itemuser`.`user_id` = 87 AND `contacts_itemuser`.`symmetry` = 2 ) | |
AND | |
`contacts_item`.`account_type` = 'facebook' | |
AND | |
( | |
(contacts_itemcandidate.candidate_id is null or contacts_itemcandidate.candidate_id = 885) | |
OR | |
(contacts_itemdistrict.district_id is null or contacts_itemdistrict.district_id = 635) | |
) | |
ORDER BY `is_voter` DESC, `social_like` DESC, `in_district` DESC, `contacts_item`.`num_votes` DESC, `contacts_item`.`name` ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment