Created
November 4, 2010 20:02
-
-
Save tcocca/663089 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 leads.id, | |
(SELECT COUNT(*) FROM searches WHERE lead_id = leads.id) AS searches_count, | |
(SELECT COUNT(*) FROM rental_searches WHERE lead_id = leads.id) AS rental_searches_count, | |
COALESCE((searches_count + rental_searches_count), 0) as total | |
FROM leads | |
WHERE leads.id = 35 | |
# Unknown column 'searches_count' in 'field list' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're really doing only running this query at any one time for a specific lead.id then it's probably better to just specify the id in the sub-queries. Also, make sure you have indexes on lead_id on the searches and rental_searches table.