ballhogjoni Posted December 30, 2008 Share Posted December 30, 2008 SELECT c.id ,sum(cs.sale_count) - sum(cs.nosale_count) as sales FROM travel_companies c,travel_company_sales cs WHERE approved = 1 AND deleted = 0 AND c.id IN (3575,182,15,701,4550) AND (c.name LIKE '%sport%' OR c.code LIKE '%sport%') ORDER BY cs.sales asc LIMIT 0,5; I get an error saying that cs.sales is unknown column Quote Link to comment https://forums.phpfreaks.com/topic/138931-whats-wrong-with-this-query/ Share on other sites More sharing options...
flyhoney Posted December 30, 2008 Share Posted December 30, 2008 FROM travel_companies as c,travel_company_sales as cs Quote Link to comment https://forums.phpfreaks.com/topic/138931-whats-wrong-with-this-query/#findComment-726579 Share on other sites More sharing options...
ballhogjoni Posted December 30, 2008 Author Share Posted December 30, 2008 FYI: the AS does not matter, thx tho Quote Link to comment https://forums.phpfreaks.com/topic/138931-whats-wrong-with-this-query/#findComment-726582 Share on other sites More sharing options...
Mark Baker Posted December 30, 2008 Share Posted December 30, 2008 I get an error saying that cs.sales is unknown column Is there a column called sales in the travel_company_sales table, or are you trying to sort on the result of sum(cs.sale_count) - sum(cs.nosale_count)? Quote Link to comment https://forums.phpfreaks.com/topic/138931-whats-wrong-with-this-query/#findComment-726589 Share on other sites More sharing options...
ballhogjoni Posted December 30, 2008 Author Share Posted December 30, 2008 trying to sort on the result of sum(cs.sale_count) - sum(cs.nosale_count)? This...I figured it out. I took off the cs. which makes sense! Quote Link to comment https://forums.phpfreaks.com/topic/138931-whats-wrong-with-this-query/#findComment-726594 Share on other sites More sharing options...
Maq Posted December 30, 2008 Share Posted December 30, 2008 Maybe it's conflicting between as sales and then trying to access cs.sales ??? Quote Link to comment https://forums.phpfreaks.com/topic/138931-whats-wrong-with-this-query/#findComment-726595 Share on other sites More sharing options...
premiso Posted December 30, 2008 Share Posted December 30, 2008 SELECT c.id ,(sum(cs.sale_count) - sum(cs.nosale_count)) as sum_sales FROM travel_companies c,travel_company_sales cs WHERE approved = 1 AND deleted = 0 AND c.id IN (3575,182,15,701,4550) AND (c.name LIKE '%sport%' OR c.code LIKE '%sport%') ORDER BY sum_sales asc LIMIT 0,5; Should produce the desired result, note the change of the column to sum_sales. Since you have a column called sales in another table, that is the best way to do it to make sure you know what you are calling. Quote Link to comment https://forums.phpfreaks.com/topic/138931-whats-wrong-with-this-query/#findComment-726598 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.