May 24, 2012 at 6:42 am
paul.knibbs (5/24/2012)
This is something I pretty much never bother to remember, because if there's any ambiguity I always add parentheses...makes it easier for humans to understand that way.
I get you, but for e.g. "OR has precedence over NOT" in T-SQL is not a fact. That was my comment about the QotD.
Igor Micev,My blog: www.igormicev.com
May 24, 2012 at 6:43 am
IgorMi (5/24/2012)
I get you, but for e.g. "OR has precedence over NOT" in T-SQL is not a fact. That was my comment about the QotD.
Sorry...my post wasn't intended to be a direct answer to yours, just a general observation!
May 24, 2012 at 7:02 am
Toreador (5/24/2012)
I can't believe that 21% have currently got it completely wrong, thinking that OR has precedence over AND! Hopefully they're just all misunderstanding what 'precedence' means π
I think that's what it is... I got it wrong.
The description makes sense... but I was looking at it as
A AND B OR C
In order to return from the select either A AND B must be true, OR C must be true.
since C isn't constrained by A AND B, the OR has precedence. π
Of course I misread the whole question and was thinking preference... heh...
I'm sure I thought of it wrong... obviously... but knowing how they work together and remembering what the definition of precedence is are really two different things.
May 24, 2012 at 7:07 am
L' Eomot InversΓ© (5/24/2012)
DugyC (5/24/2012)
Basic computer science question, nice and easy, thanks.Can't believe almost a third got it wrong!
Bak to skool! π
"computer science" question? Since when was T-SQL operator precedence part of computer science? Do you think that all computer languages give AND precedence over OR? If so you will be surprised when you come across languages that give OR precedence over AND, languages that have left to right precedence, languages that have right to left precedence, and languages where not fixing evaluation order by overt syntactic means (using brackets or dots) is a syntax error.
LOL!! That's brilliant Tom, yeesh! :rolleyes:
However, to answer your questions...
Since when was T-SQL operator precedence part of computer science?
It's not but if you remove "T-SQL" it is.
Do you think that all computer languages give AND precedence over OR?
No I don't
_____________________________________________________________________
[font="Comic Sans MS"]"The difficult tasks we do immediately, the impossible takes a little longer"[/font]
May 24, 2012 at 7:12 am
I'm with a couple of the guys here and I actually had to dig down into the think tank a little to remember it. I'd never write anything (or at least attempt to) without parenthesis to begin with, so it was actually a pretty nice challenge to remember it especially with it being so early. But, thanks to the QotD, my brain juices are flowing and I can start my day. π
May 24, 2012 at 7:13 am
L' Eomot InversΓ© (5/24/2012)
DugyC (5/24/2012)
Basic computer science question, nice and easy, thanks.Can't believe almost a third got it wrong!
Bak to skool! π
"computer science" question? Since when was T-SQL operator precedence part of computer science? Do you think that all computer languages give AND precedence over OR? If so you will be surprised when you come across languages that give OR precedence over AND, languages that have left to right precedence, languages that have right to left precedence, and languages where not fixing evaluation order by overt syntactic means (using brackets or dots) is a syntax error.
I had exactly the same reaction to this idea that there is some sacred order in CS for AND and OR. I think this might be a question of assuming that the language you know best represents the way things "ought" to be. I've written code in 20+ languages (probably way less than Tom), and have just come to assume that they all have shortcomings! π
[font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
Connect to me on LinkedIn
May 24, 2012 at 7:30 am
Nice question! Order of operations π
May 24, 2012 at 7:34 am
Thank you again for all your comments and feedback!
I came up with question after seeing some code written by a colleague who had omitted to use brackets in the WHERE clause.
:exclamation: "Be brave. Take risks. Nothing can substitute experience." :exclamation:
May 24, 2012 at 7:45 am
mtassin (5/24/2012)
Toreador (5/24/2012)
I can't believe that 21% have currently got it completely wrong, thinking that OR has precedence over AND! Hopefully they're just all misunderstanding what 'precedence' means πI think that's what it is... I got it wrong.
The description makes sense... but I was looking at it as
A AND B OR C
In order to return from the select either A AND B must be true, OR C must be true.
since C isn't constrained by A AND B, the OR has precedence. π
Of course I misread the whole question and was thinking preference... heh...
I'm sure I thought of it wrong... obviously... but knowing how they work together and remembering what the definition of precedence is are really two different things.
That's exactly how I was thinking about it too.
May 24, 2012 at 9:07 am
An easy one - thanks!
May 24, 2012 at 9:50 am
Nice easy one, thanks!
May 24, 2012 at 10:01 am
nice, straight forward questions today - cheers
May 24, 2012 at 7:28 pm
JiCiT (5/24/2012)
mtassin (5/24/2012)
Toreador (5/24/2012)
I can't believe that 21% have currently got it completely wrong, thinking that OR has precedence over AND! Hopefully they're just all misunderstanding what 'precedence' means πI think that's what it is... I got it wrong.
The description makes sense... but I was looking at it as
A AND B OR C
In order to return from the select either A AND B must be true, OR C must be true.
since C isn't constrained by A AND B, the OR has precedence. π
Of course I misread the whole question and was thinking preference... heh...
I'm sure I thought of it wrong... obviously... but knowing how they work together and remembering what the definition of precedence is are really two different things.
That's exactly how I was thinking about it too.
Add me to this list too. I answered OR having higher precedent than AND because it doesn't matter what the evaluation of one side of the OR is if the other side evaluates true therefore the OR is of a higher "precedent", but I didn't take into account how Microsoft defines "precedent". Oh well.
May 24, 2012 at 7:40 pm
Good question. I learned something today. Thanks for submitting.
http://brittcluff.blogspot.com/
May 24, 2012 at 8:18 pm
mtassin (5/24/2012)I think that's what it is... I got it wrong.
The description makes sense... but I was looking at it as
A AND B OR C
In order to return from the select either A AND B must be true, OR C must be true.
since C isn't constrained by A AND B, the OR has precedence. π
Of course I misread the whole question and was thinking preference... heh...
I'm sure I thought of it wrong... obviously... but knowing how they work together and remembering what the definition of precedence is are really two different things.
Ahh, someone else got it wrong.
I was afraid of posting anything because almost everyone stated this was an easy question. But I was thinking along the same line: the OR operator will "overcome" all of the AND operators in the end. :hehe:
Best regards,
Andre Guerreiro Neto
Database Analyst
http://www.softplan.com.br
MCITPx1/MCTSx2/MCSE/MCSA
Viewing 15 posts - 16 through 30 (of 40 total)
You must be logged in to reply to this topic. Login to reply