Mysql LEAST comparison function help


Using this example, I get the error
'! FUNCTION database.least does not exist.'

select surname, firstname, YTD
From dumpme
where YTD=least (@ytd1, @ytd2);

I have 2 parts to this question.

a) could someone help me get the syntax correct

b)Could someone explain to me what the (@ytd1, ytd2) is actually doing
   so i can understand what LEAST (@ytd1, ytd2)  does!

Thanks

LVL 8
kingjelyAsked:
Who is Participating?
 
Om PrakashCommented:
I think there is space between least & (
Try  
select least(2,0);
instead of
select least (2,0);

there should not be space between least and (...
0
 
Praveen VenuTechnical Project ManagerCommented:
select surname, firstname, YTD
From dumpme
where YTD=(select least (@ytd1, @ytd2));

Least will return the least value from the values you passed to least function.
0
 
kingjelyAuthor Commented:
Okay i tried this, as you have it

select surname, firstname, YTD
From dumpme
where YTD =(select least (@ytd1, @ytd2));

But it stil thinks that least is a table_name

ERROR
'! FUNCTION database.least does not exist'
0
Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

 
kingjelyAuthor Commented:

If i comment out the where line, i get results.

select surname, firstname, YTD
From dumpme
#where YTD =(select least (@ytd1, @ytd2));

But with the  Where line i get

ERROR
'! FUNCTION database.least does not exist'
0
 
Om PrakashCommented:
select surname, firstname, YTD
From dumpme
where YTD = least(1,3,4,5);

assuming YTD is numeric

Least returns the smallest argument

Example:
SELECT LEAST(2,0);
this will return
0

SELECT LEAST('B','A','C');
this will return
'A'

http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_least
0
 
kingjelyAuthor Commented:
Ahh Okay cool,

I understand what it does a little better, though, for some reason

with this code
select least (2,0);

I keep getting this error

ERROR
'! FUNCTION database.least does not exist'

why does Mysql think that least is a field name, how to get a result with-out an error !
0
 
kingjelyAuthor Commented:

This is the version number of mysql

select version()
>5.0.24a-log

and LEAST is a reserved word(it turns blue)
0
 
kingjelyAuthor Commented:

Ah yep very clever!

So to find the LEAST value in YTD,

why could i not use this?

select surname, firstname, YTD
From dumpme
where YTD = least(YTD);
0
 
Om PrakashCommented:
You can use MIN for this

select surname, firstname, YTD
From dumpme
where YTD = (SELECT min(YTD) from dumpme);

LEAST requires atleast 2 parameters

Example:
select surname, firstname, YTD
From dumpme
where YTD = least(YTD, 100);

0
 
kingjelyAuthor Commented:

Thanks I got this lastnight, but forgot to award points
Thanks Om !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.