Skip to content
Advertisement

Order of Procedure for Select statement with Where Clause and other operators

This is the table I’m working off:

From this order of procedure that was provided in class:

  1. Parentheses
  2. */
  3. +-
  4. = <= >= < >
  5. IS
  6. Between
  7. NOT
  8. AND
  9. OR

I have to work out how many rows of the following statement with show up:

Is this statement read in this order:

  1. QtyA+QtyB
  2. QtyA+QtyB < 5
  3. gender = ‘F’
  4. gender = ‘M’
  5. gender = ‘M’ AND QtyA+QtyB < 5
  6. gender = ‘F’ OR gender = ‘M’

My logic that is probably wrong is:

  1. Since no parentheses it does the addition first – QtyA+QtyB
  2. Then it does < operator as it’s the next one on that list given to me < 5.
  3. Then it does the = which is gender = ‘F’
  4. Then gender = 'M' as it’s the next equal
  5. Then it does the AND operator so gender = 'M' AND QtyA+QtyB
  6. Finally it does the OR operator then gender = 'F' OR gender = 'M'

So 0 rows will show up after step 5

The next test apparently has a large section where you have to read Select statements and find how many rows will show from them without typing anything in and I feel like I’m doing this completely wrong, but I came up with 0 which is what the select statement gave me when I type it in.

Advertisement

Answer

You want to apply parentheses. The query as written is expressing:

That is because AND has higher precedence than OR. Then arithmetic operations are going to be evaluated before comparisons.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement