Re: [PHP-DB] Idea as to why this query won't work as expected?

2002-11-05 Thread Thomas Lamy
Dave Smith [mailto:DavidSmith@;byu.net] wrote:
> 
> I can never remember whether SQL is left-to-right, right-to-left, or 
> some other deviant. Using parens is a sure way to guarantee that your 
> statements are processed in the order you desire.
> 
> --Dave
> 
It's easy if you remember: AND is equal to multiplication, OR is equal to
addition. Multiplications are done before additions, so ANDs are done before
ORs.

Thomas

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Idea as to why this query won't work as expected?

2002-11-05 Thread Aaron Wolski
Hi there,

This worked perfectly for me!

Thanks for the tip - I shall remember this :)

To all who replied - thanks for your help as well.

Regards,

Aaron



> -Original Message-
> From: Ignatius Reilly [mailto:ignatius.reilly@;free.fr] 
> Sent: Tuesday, November 05, 2002 9:15 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] Idea as to why this query won't work as 
> expected?
> 
> 
> AND/ OR precedence mistake. Your query will return all the 
> rows for which order_status='Not Shipped' 
> 
> Probably what you want is:
> 
> select * FROM OrderTable WHERE submitted=1 AND
> dateinserted>='1036386000' AND dateinserted<='1036502796' AND
> ( order_status='Shipped' OR order_status='Not Shipped' )
> 
> HTH
> Ignatius J. Reilly
> 
> - Original Message - 
> From: "Aaron Wolski" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, November 05, 2002 2:59 PM
> Subject: [PHP-DB] Idea as to why this query won't work as expected?
> 
> 
> > Hi All,
> >  
> > I have a query like:
> >  
> > select * FROM OrderTable WHERE submitted=1 AND
> > dateinserted>='1036386000' AND dateinserted<='1036502796' AND
> > order_status='Shipped' OR order_status='Not Shipped'
> >  
> >  
> > Now.. if I omit the  "AND order_status='Shipped' OR 
> order_status='Not 
> > Shipped'" part the query works fine and only returns 2 results (as 
> > expected). However, with the inclusion of the previous I 
> get all the 
> > results (currently 8) returned.
> >  
> > It seems to be ignoring everything before "AND 
> order_status='Shipped' 
> > OR order_status='Not Shipped'".
> >  
> > Any clues?
> >  
> > Much thanks!
> >  
> > Aaron
> > 
> 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Idea as to why this query won't work as expected?

2002-11-05 Thread Josh Johnson
The or part should be in parens. Your bascialy saying grab everything
that has order_status='Shipped' and your date requirements, OR
everything where order_status is equal to 'Not Shipped'...

-- Josh

-Original Message-
From: Aaron Wolski [mailto:aaronjw@;martekbiz.com] 
Sent: Tuesday, November 05, 2002 9:00 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Idea as to why this query won't work as expected?

Hi All,
 
I have a query like:
 
select * FROM OrderTable WHERE submitted=1 AND
dateinserted>='1036386000' AND dateinserted<='1036502796' AND
order_status='Shipped' OR order_status='Not Shipped'
 
 
Now.. if I omit the  "AND order_status='Shipped' OR order_status='Not
Shipped'" part the query works fine and only returns 2 results (as
expected). However, with the inclusion of the previous I get all the
results (currently 8) returned.
 
It seems to be ignoring everything before "AND order_status='Shipped' OR
order_status='Not Shipped'".
 
Any clues?
 
Much thanks!
 
Aaron


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Idea as to why this query won't work as expected?

2002-11-05 Thread Dave Smith
Try grouping your WHERE clauses with parentheses like so:

select * FROM OrderTable WHERE ( submitted=1 AND
dateinserted>='1036386000' AND dateinserted<='1036502796' AND
order_status='Shipped' ) OR order_status='Not Shipped'

I can never remember whether SQL is left-to-right, right-to-left, or 
some other deviant. Using parens is a sure way to guarantee that your 
statements are processed in the order you desire.

--Dave

Aaron Wolski wrote:
Hi All,
 
I have a query like:
 
select * FROM OrderTable WHERE submitted=1 AND
dateinserted>='1036386000' AND dateinserted<='1036502796' AND
order_status='Shipped' OR order_status='Not Shipped'
 
 
Now.. if I omit the  "AND order_status='Shipped' OR order_status='Not
Shipped'" part the query works fine and only returns 2 results (as
expected). However, with the inclusion of the previous I get all the
results (currently 8) returned.
 
It seems to be ignoring everything before "AND order_status='Shipped' OR
order_status='Not Shipped'".
 
Any clues?
 
Much thanks!
 
Aaron





--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Idea as to why this query won't work as expected?

2002-11-05 Thread Ignatius Reilly
AND/ OR precedence mistake. Your query will return all the rows for which
order_status='Not Shipped' 

Probably what you want is:

select * FROM OrderTable WHERE submitted=1 AND
dateinserted>='1036386000' AND dateinserted<='1036502796' AND
( order_status='Shipped' OR order_status='Not Shipped' )

HTH
Ignatius J. Reilly

- Original Message - 
From: "Aaron Wolski" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 05, 2002 2:59 PM
Subject: [PHP-DB] Idea as to why this query won't work as expected?


> Hi All,
>  
> I have a query like:
>  
> select * FROM OrderTable WHERE submitted=1 AND
> dateinserted>='1036386000' AND dateinserted<='1036502796' AND
> order_status='Shipped' OR order_status='Not Shipped'
>  
>  
> Now.. if I omit the  "AND order_status='Shipped' OR order_status='Not
> Shipped'" part the query works fine and only returns 2 results (as
> expected). However, with the inclusion of the previous I get all the
> results (currently 8) returned.
>  
> It seems to be ignoring everything before "AND order_status='Shipped' OR
> order_status='Not Shipped'".
>  
> Any clues?
>  
> Much thanks!
>  
> Aaron
> 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Idea as to why this query won't work as expected?

2002-11-05 Thread Aaron Wolski
Hi All,
 
I have a query like:
 
select * FROM OrderTable WHERE submitted=1 AND
dateinserted>='1036386000' AND dateinserted<='1036502796' AND
order_status='Shipped' OR order_status='Not Shipped'
 
 
Now.. if I omit the  "AND order_status='Shipped' OR order_status='Not
Shipped'" part the query works fine and only returns 2 results (as
expected). However, with the inclusion of the previous I get all the
results (currently 8) returned.
 
It seems to be ignoring everything before "AND order_status='Shipped' OR
order_status='Not Shipped'".
 
Any clues?
 
Much thanks!
 
Aaron