Sean R
Sean R

Reputation: 31

Why am I getting a error on this if statement?

select if
(
(min(student_number)>1) or (max(student_number)<5500),'ok','Check Students'
)
from students;

Upvotes: 0

Views: 54

Answers (3)

JayDM
JayDM

Reputation: 1186

There is a third alternative if you want to test that it is within a range. Use between.

select if(student_number between 1 and 5500, 'Ok', 'Check Students') from students;

As long as there are any rows in your table - that will work. If there are no rows, then you will get an empty set.

Upvotes: 0

Bohemian
Bohemian

Reputation: 424983

Try this:

select if(min_sn > 1 or max_sn < 5500, 'ok', 'Check Students')
from (select 
        min(student_number) as min_sn,
        max(student_number) as max_sn
      from students) x

This will perform reasonably well too.

Note: It seems almost certain you should use and instead of or in your test. Think about it...

Upvotes: 0

M Abbas
M Abbas

Reputation: 6479

You should replace OR By AND:

select if
(
(min(student_number)>1) and (max(student_number)<5500),'ok','Check Students'
)
from students;

Upvotes: 1

Related Questions