amites Posted April 9, 2008 Share Posted April 9, 2008 Hello, This one might make ya think, been racking my blain, example of what I want to do: SELECT cit.english name, Count(s.id) cnt FROM bil_cities AS cit Join bil_location AS loc ON loc.city_id = cit.id Join bil_msg_sent AS s ON s.locid = loc.id WHERE cit.state_id = '13' GROUP BY cit.id ORDER BY name ASC DB Structure: cities (every city in the US), location (contains, city_id, and loc_id) bil_msg_sent (what I'm trying to count based on id & loc_id) I'm trying to complete that query with Left Joins for bil_location and bil_msg_sent to have a complete list of Cities within a given state, of course once I change them to a Left Join it ignores the Where statement and tries to pull every city in the table, any ideas? Quote Link to comment Share on other sites More sharing options...
fenway Posted April 10, 2008 Share Posted April 10, 2008 Because you then need to move you where clause to the on clause. Quote Link to comment Share on other sites More sharing options...
amites Posted April 12, 2008 Author Share Posted April 12, 2008 heh, originally tried doing that with FROM bil_city as cit ON cit.state_id = '13' = SQL error --- then I realized that the state_id is also in the bil_location table added an AND to the on clause for that line and boo yeah --- thank you for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.