don't know how to search for what i'm looking for - i need to SELECT a numerical value from a table with a +/- allowance (WHERE 'width' = $width +/- 2). can someone help me with this simple query?
thanks much
GN
query for value with allowance
Moderator: General Moderators
-
minorDemocritus
- Forum Commoner
- Posts: 96
- Joined: Thu Apr 01, 2010 7:28 pm
- Location: Chicagoland, IL, USA
Re: query for value with allowance
Code: Select all
SELECT * FROM `tablename` WHERE 'width' <= ( $width + 2 ) AND 'width' >= ( $width - 2 )
Re: query for value with allowance
I ended up with WHERE width (between ($w - 2) AND ($w + 2)) AND length (between ($l - 2) AND ($l + 2)); and it seems to work - is there any efficiency benefit to your way over "between"? PHP versions, etc...?
thanks for you help.
gn
thanks for you help.
gn
-
minorDemocritus
- Forum Commoner
- Posts: 96
- Joined: Thu Apr 01, 2010 7:28 pm
- Location: Chicagoland, IL, USA
Re: query for value with allowance
That's hard to say. Try it! If you have phpMyAdmin, when you run direct SQL queries, it will tell you:
Showing rows 0 - 5 (6 total, Query took 0.0147 sec)
Do it a few times, though, and average the times to account for server load changes, etc.
Showing rows 0 - 5 (6 total, Query took 0.0147 sec)
Do it a few times, though, and average the times to account for server load changes, etc.
-
minorDemocritus
- Forum Commoner
- Posts: 96
- Joined: Thu Apr 01, 2010 7:28 pm
- Location: Chicagoland, IL, USA
Re: query for value with allowance
...And please PLEASE use the [ syntax=sql ] bbcode so our eyes don't bleed 
Re: query for value with allowance
minorDemocritus wrote:...And please PLEASE use the [ syntax=sql ] bbcode so our eyes don't bleed
you got it - sorry - thanks!