Step 6/9: Id = 2: MIN/MAX error?


#1

If you look at the table of this query

SELECT 
  id, 
  MIN(cook_time, cool_down_time), 
  MAX(cook_time, cool_down_time)
FROM baked_goods
LIMIT 4;

The row with the id as 2 has 5 as MAX and 33 as MIN ???
Can someone explain why is this happening with the row with an id as 2?

EDIT:
I created a table that filters this mistake, because I noticed that other ids have this problem:

SELECT 
  id [IDs with a mistake],
  MAX(cook_time, cool_down_time) as MAXc, 
  MIN(cook_time, cool_down_time) as MINc
FROM baked_goods
WHERE MAXc/MINc < 1;

#2

That's a good way to write code Jkaybro, ensures no nulls on the report but won't work here because cook and cool are text fields (error making database). So instead of < 1 it would be IS NOT NULL.


#3

The < 1 was stated on a division of two aliases that I created:
MAXc = MAX(cook_time, cool_down_time) ,
MINc = MIN(cook_time, cool_down_time),
both are integers.

I wrote WHERE MAXc/MINc < 1 to see which row has the MAX as the lower number and MIN as the highest number.

The filter works because a higher number divided by a lower number can't be less than 1, thus, because some rows have the MAX and MIN values switched, this condition will return TRUE for the rows who has this inversion.


#4