I have two Oracle tables:
USER(ID*,NAME,SURNAME)
MATCH(ID*,START_DATE,END_DATE,MATCH_CODE,ID_USER**)
I need a query to get for each USER the match with the maximum difference in seconds between END_DATE and START_DATE and in addition the NAME and MATCH_CODE fields.
My query:
SELECT A.ID,A.NAME,MAX(extract(second from (END_DATE-START_DATE))
+ extract(minute from (END_DATE-START_DATE)*60
+ extract(hour from (END_DATE-START_DATE)*60*60
+ extract(day from (END_DATE-START_DATE)*60*60*24) max_differance
FROM USER A JOIN MATCH B
ON A.ID = B.ID_USER
GROUP BY A.ID;
I was thinking about this query but obviously it gives an error because in the GROUP BY all the fields of the select go. Also I would need the MATCH_CODE field, how should I do?