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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.