Results 1 to 3 of 3
Thread: Order by count
Nov 21, 2012, 04:20 #1
- Join Date
- Jan 2005
- 0 Post(s)
- 0 Thread(s)
Order by count
I have a query that orders results by the count of another table:
"SELECT table1.*, COUNT(table2.id) AS rev_count FROM table1
LEFT JOIN table2 ON table1.name = table2.name
WHERE table1.active = 1 AND table1.city='$city'
GROUP BY table1.name
ORDER BY rev_count DESC";
How do you add a condition (ie WHERE active=1) to just the "COUNT(table2.id) AS rev_count" part of the query?