Almost finished with a project - but I am stumped (and no worldly amount of
caffeine could keep me up longer.)
Have a situation where I need to query the database on a single table
(Snackers) but looking at three fields.
Field1=CustomerName (Johnny Junkie)
Field2=LikesMMs (Yes/NULL)
Field3=LikesSnickers (Yes/NULL)
Always need to match CustomerName to "Johnny Junkie" value, but want to get
either or both of Field2/Field3 if they contain "Yes".
Here is my flawed query:
SELECT Dentist, PhoneNumber FROM Snackers WHERE CustomerName='Johnny Junkie'
AND LikesMMs='Yes' OR LikesSnickers='Yes'
This gives me Johnny's Dentist only if Johnny likes M&Ms, and to my dismay -
*any* other snack-lover that likes Snickers - DOLT!!!
The right syntax would give me *only* Johnny's preferences for M&M's,
Snickers, or both.
Any clues - Thanx a bunch! Trying to avoid two separate queries...
John
"Chuck Joslin - <<TNO/TGF>>" <ch...@gotfusion.com> wrote in message news:agja69$ha...@news01.netobjects.com...
"Chuck Joslin - <<TNO/TGF>>" <ch...@gotfusion.com> wrote in message news:agjb9f$ha...@news01.netobjects.com...
"Chuck Joslin - <<TNO/TGF>>" <ch...@gotfusion.com> wrote in message news:agjb9f$ha...@news01.netobjects.com...
"Chuck <<TNO/TGF>>" <ch...@gotfusion.com> wrote in message news:agkedu$hf...@news01.netobjects.com...Travis -SQL is a funny thing. The answer depends on the implementation.I've experimented a bit with this a long time ago and found that x OR y AND Z does indeed produce x OR (y AND z) in some SQL dialects. I started using SQL in Access, so 'nuff said about that!Removing ambiguity thru use of parentheses makes it a moot issue. I haven't experimented with it in MySQL recently. I learned long ago to just enclose operators appropriately to get the results I'm looking for.To the technically astute, saying "AND takes precedence over OR in a query constructed like yours because it comes first, so your original one was acting like this:" would have been more accurate. Hey...it was 3AM when I wrote that. Gimme a break! (-:
Awave, Inc., Orlando, Florida USA
=============================
Fusion 7/PHP/MySQL Tutorial
http://www.awave.net/html/fusiontutorials.php
"Travis Elkins" <travis...@REMOVETHISphoenix.com> wrote in message news:agkc90$hf...@news01.netobjects.com...
"Travis Elkins" <travis...@REMOVETHISphoenix.com> wrote in message news:agkc90$hf...@news01.netobjects.com...
"John Williams" <jwil...@hotwirecommunications.com> wrote in message news:agjtfd$ha...@news01.netobjects.com...