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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.