So I’m tasked with writing a few SQL queries that involve finding the highest or lowest value in a grouping without using aggregate functions. For example, I have the following table:
Ages:
Name Age
John 21
Bill 30
Laura 19
Timothy 23
Victoria 29
Say I wanted to query the oldest person in the table (in this case Bill) without using aggregate functions (i.e. count, group, etc…)
EDIT I also cannot use groupings in my queries! I didn’t make that distinction very clear in my first post, my apologies =/
I’m having trouble getting past:
SELECT name
FROM Ages
WHERE Ages.Age IN (
SELECT a1.Age
FROM Age a1, Age a2
WHERE a1.Age > a2.Age);
Obviously my query is no good here… I was wondering if someone could point me in the direction of a useful SQL function or piece of logic that might help me with this type of query.
Thank you for your help.
This should work in most DBMS:
Fiddle here