Aravinthan Posted August 20, 2009 Share Posted August 20, 2009 Hi guys, I was wondering, I have this MYSQL Select code: SELECT * FROM `schedule` WHERE `month` = '12 'AND `year`='2009' AND `home_team`='16' OR `away_team`='16' ORDER BY `day` ASC It shows results from every month and every year... Why is that? The only 2 thing that it takes into consideration is the home_team and away_team and the Order By.... Quote Link to comment https://forums.phpfreaks.com/topic/171201-solved-sql-help/ Share on other sites More sharing options...
Julian Posted August 20, 2009 Share Posted August 20, 2009 Are `month` and `year` separate columns on your sql structure? or are you using a date column that contains the month and year? Quote Link to comment https://forums.phpfreaks.com/topic/171201-solved-sql-help/#findComment-902815 Share on other sites More sharing options...
Aravinthan Posted August 20, 2009 Author Share Posted August 20, 2009 year and month are seperate colums Here is the colums: -id -year -month -home_team -away_team and there is more Quote Link to comment https://forums.phpfreaks.com/topic/171201-solved-sql-help/#findComment-902826 Share on other sites More sharing options...
Julian Posted August 20, 2009 Share Posted August 20, 2009 Have you tried using: SELECT DISTINCT or GROUP BY? Quote Link to comment https://forums.phpfreaks.com/topic/171201-solved-sql-help/#findComment-902831 Share on other sites More sharing options...
Aravinthan Posted August 20, 2009 Author Share Posted August 20, 2009 How can Group By be useful here? Quote Link to comment https://forums.phpfreaks.com/topic/171201-solved-sql-help/#findComment-902836 Share on other sites More sharing options...
Aravinthan Posted August 20, 2009 Author Share Posted August 20, 2009 I need the whole table information, There is some game results that I have to get in a while Loop(php) Quote Link to comment https://forums.phpfreaks.com/topic/171201-solved-sql-help/#findComment-902837 Share on other sites More sharing options...
kickstart Posted August 20, 2009 Share Posted August 20, 2009 Hi Problem is down to the precedence of AND and OR. MySQL evaluates the ANDs first and then the OR. Use brackets to force the issue:- SELECT * FROM `schedule` WHERE `month` = '12 ' AND `year`='2009' AND (`home_team`='16' OR `away_team`='16' ) ORDER BY `day` ASC All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/171201-solved-sql-help/#findComment-902845 Share on other sites More sharing options...
Aravinthan Posted August 20, 2009 Author Share Posted August 20, 2009 Oh wow thank you so much!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/171201-solved-sql-help/#findComment-902852 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.