JElster
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
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
SELECT GREATEST(field1,fiedl2, field3, field4) from yourtable
put semi colon after:
SELECT GREATEST(field1,fiedl2, field3, field4) from yourtable;
ASKER
I need the user associated with the Greatest value
Try this and see if it solves your problem.
yourtable t1 and t2 are same table.
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
yourtable t1 and t2 are same table.
ASKER
Sorry,. I need the GREATEST VALUE and USER
So it returns
8/4/2014 Mike
thx
So it returns
8/4/2014 Mike
thx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.