Jump to content

mysql query


gusmacker

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/2589-mysql-query/
Share on other sites

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 >= <=))"

Link to comment
https://forums.phpfreaks.com/topic/2589-mysql-query/#findComment-8585
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/2589-mysql-query/#findComment-8586
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.