Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Comparrisons - AND/OR and combinations thereof 3

Status
Not open for further replies.

kjv1611

New member
Jul 9, 2003
10,758
US
This probably ought to be a silly easy question, and I feel pretty dumb for asking, but I just can't seem to remember, and am not totally sure.

Basically, let me sum it up in an example:

Would this:
Code:
SELECT a.FruitID 
FROM tblFruit a
WHERE (a.FruitColor = Red)
         OR
      (a.FruitWeight = 2)

Return the same as this:
Code:
SELECT a.FruitID 
FROM tblFruit a
WHERE (a.FruitColor = Red)
         OR
      (a.FruitWeight = 2)
         OR
      (
         (a.FruitColor = Red)
            AND
         (a.FruitWeight = 2)
      )
???

Any ideas, there?

Or am I making any sense at all?

I'm mainly wanting to make sure that if I leave out the 3rd "OR" conditional grouping that contains 2 different contitions, that I am not leaving out possible records...

So, in the example, I'd like to pull all records, whether they match any or all of the criteria.

Thanks for any thoughts/ideas/suggestions...

--

"If to err is human, then I must be some kind of human!" -Me
 
Those queries will return the same results. It's all in the parentheses. Remember to put single quotes around your string criteria.
 
The first two parts of your query would get everything (plus a lot more) then the third part of the query.

Joe Schwarz
Custom Software Developer
 
I'd also recommend that if you're in doubt, create yourself some sample data, and put it in a table. Run the queries against the data, with a priori knowledge of what the outcome should be, and see if results are as expected.

In a nutshell, write some simple manual unit tests.

Regards

T
 
Thanks for the responses. I appreciate the information, including the idea to test some sample data. As the data results can be very important, I suppose that would be in order in at least some scenarios.

Those answers were what I supposed was the case, but I started to thinking... but what if the set like that ONLY returned results where one criterion or the other were true.

And as I was just now thinking about it, I think I just solved it in my own head - imagine that! LOL

Thanks again!

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top