Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Need a little help with mySQL where_clause

Need a little help with mySQL where_clause
Thread Tools
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Feb 21, 2004, 12:38 PM
 
I'm having a bit of trouble with a mySQL where_clause. I thought maybe laying out the logic similar to PHP might work, but I get a syntax error. Looked in the manual and could not find anything relevant to the type of where_clause I want to do.

What I want to do is query an order info table and select from it all orders that were either created or last modified between 2 given dates. Here is the syntax I was hoping would work but does not:
Code:
SELECT orders_id FROM orders WHERE (date_purchased >= '" . $beginDate . "' OR last_modified >= '" . $beginDate . "') AND (date_purchased <= '" . $endDate . "' OR last_modified <= '" . $endDate . '") ORDER BY orders_id ASC
Anyone know how to tackle this sort of where_clause:
(a OR b) AND (c OR d) ?

PS. running MySQL 4.0.15
     
Fresh-Faced Recruit
Join Date: Aug 2000
Location: Birmingham, UK
Status: Offline
Reply With Quote
Feb 21, 2004, 02:29 PM
 
That should work I think - your syntax error is right at the end where you've put

Code:
'" . $endDate . '"
it should be

Code:
'" . $endDate . "'
Your single and double quotes are the wrong way round!

Hopefully it's that simple!
     
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Feb 21, 2004, 02:51 PM
 
that was just a typo in here.

I did get it working though. But I did not change anything. my SQL guru friend informed me that `where (a OR b) AND (c OR d)` syntax is fine. I tried running the query again and it worked.

Though I am still a little confused as the first 10 times I ran it, it would not work and even typing a similar query in phpMyAdmin would give and error, and where it highlights the code you put in, it was attempting to add a `limit` clause in the middle of the where_clause. It is working ok now though. Not sure what was up.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:01 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2