Jump to content


Photo

mysql query


  • Please log in to reply
2 replies to this topic

#1 gusmacker

gusmacker
  • Members
  • Pip
  • Newbie
  • 9 posts
  • LocationGrand Rapids, Michigan

Posted 30 September 2005 - 02:10 PM

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.


[php:1:09d88d0ab6]<? [br]if ($SKYDIVING == "NO") { [br]$LIFE = EMPTY; [br]} else { [br]$LIFE = "FULL OF JOY"; [br]?> [br][/php:1:09d88d0ab6]

#2 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 30 September 2005 - 03:13 PM

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

#3 gusmacker

gusmacker
  • Members
  • Pip
  • Newbie
  • 9 posts
  • LocationGrand Rapids, Michigan

Posted 30 September 2005 - 03:32 PM

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

View Post



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
[php:1:09d88d0ab6]<? [br]if ($SKYDIVING == "NO") { [br]$LIFE = EMPTY; [br]} else { [br]$LIFE = "FULL OF JOY"; [br]?> [br][/php:1:09d88d0ab6]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users