gusmacker Posted September 30, 2005 Share Posted September 30, 2005 Ok. I don't have much hair to begin with and I am pulling it all out over this dang query. SELECT * FROM `recurring` WHERE (`service_date` >= '2005-09-21' AND `service_date` <= '2005-09-28') OR (`term_date` >= '2005-09-21' AND `term_date` <= '2005-09-28') AND (`customer_number` = '0000008952') What I am trying to do is get service dates that are great then x day but less then x day or term dates that are greater then x day and less then x day and have x as a customer number. It totaly disregards the customer number and gives me all records that match the first part. what am I doing wrong. Quote Link to comment https://forums.phpfreaks.com/topic/2589-mysql-query/ Share on other sites More sharing options...
shoz Posted September 30, 2005 Share Posted September 30, 2005 Try the following. [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM `recurring` WHERE ((`service_date` >= '2005[span style=\'color:orange\']-09-21'[/span] AND `service_date` <= '2005[span style=\'color:orange\']-09-28'[/span]) OR (`term_date` >= '2005[span style=\'color:orange\']-09-21'[/span] AND `term_date` <= '2005[span style=\'color:orange\']-09-28'[/span])) AND (`customer_number` = '0000008952') [!--sql2--][/div][!--sql3--] Note the grouping of the entire "OR" "((service_date <= >=) OR (term_date >= <=))" Quote Link to comment https://forums.phpfreaks.com/topic/2589-mysql-query/#findComment-8585 Share on other sites More sharing options...
gusmacker Posted September 30, 2005 Author Share Posted September 30, 2005 Try the following. [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM `recurring` WHERE ((`service_date` >= '2005[span style=\'color:orange\']-09-21'[/span] AND `service_date` <= '2005[span style=\'color:orange\']-09-28'[/span]) OR (`term_date` >= '2005[span style=\'color:orange\']-09-21'[/span] AND `term_date` <= '2005[span style=\'color:orange\']-09-28'[/span])) AND (`customer_number` = '0000008952') [!--sql2--][/div][!--sql3--] Note the grouping of the entire "OR" "((service_date <= >=) OR (term_date >= <=))" 301329[/snapback] Thanks. I just caught that and was going to update the post as solved and I seen your response. This is the first time I have had to use brackets so i wasn't thinking about it that way. Kevin Quote Link to comment https://forums.phpfreaks.com/topic/2589-mysql-query/#findComment-8586 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.