Link to home
Start Free TrialLog in
Avatar of JElster
JElsterFlag for United States of America

asked on

Help with Query using GREATEST

Hi.
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
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

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

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

Open in new window

Avatar of JElster

ASKER

I need the user associated with the Greatest value
Try this and see if it solves your problem.

SELECT t1.user1,t1.user2,t1.user3,t1.user4
FROM yourtable t1
INNER JOIN
(
    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.
Avatar of JElster

ASKER

Sorry,. I need the  GREATEST VALUE and USER
So it returns

8/4/2014       Mike


thx
ASKER CERTIFIED SOLUTION
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial