Reputation: 31
select if
(
(min(student_number)>1) or (max(student_number)<5500),'ok','Check Students'
)
from students;
Upvotes: 0
Views: 54
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
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
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