Help with Query using GREATEST

I have data that looks like this:  I need to return the GREATEST date (most current) along with the USER associated with the date. So I want to return 2 fields   DATE & USER

FIELD1     USER1           FIELD2         USER2           FIELD3         USER3
1/1/2001    BOB           1/4/2013       JANE            8/4/2014       MIKE

Should return
8/4/2014       Mike
Who is Participating?
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.

SELECT GREATEST(field1,fiedl2, field3, field4) from yourtable
put semi colon after:

SELECT GREATEST(field1,fiedl2, field3, field4) from yourtable;

Open in new window

JElsterAuthor Commented:
I need the user associated with the Greatest value
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Try this and see if it solves your problem.

SELECT t1.user1,t1.user2,t1.user3,t1.user4
FROM yourtable t1
    SELECT GREATEST(field1,field2,fiel3,fiel4)
    FROM yourtable t2
) t2 ON t1.ID=t2.ID

Open in new window

yourtable t1 and t2 are same table.
JElsterAuthor Commented:
Sorry,. I need the  GREATEST VALUE and USER
So it returns

8/4/2014       Mike

Daniel WilsonCommented:
Select GREATEST (Field1, field2, Field3) as GreatestDate,
CASE WHEN field1 = GREATEST (Field1, field2, Field3) then User1
WHEN field2 = GREATEST (Field1, field2, Field3) then User2
WHEN field3 = GREATEST (Field1, field2, Field3) then User3
END as GreatestUser
From MyTable;

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

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.