Sobes.tech
Senior

SQL task: there is a table users with columns userid, name, age. Find the ID of the oldest user.

sobes.tech AI

Answer from AI

To find the ID of the oldest user in the users table, you can use an SQL query sorted by age with a limit of one record:

SELECT userid
FROM users
ORDER BY age DESC
LIMIT 1;

This query sorts users by descending age and returns the userid of the oldest.

If you need to consider that there may be multiple users with the maximum age, you can use a subquery:

SELECT userid
FROM users
WHERE age = (SELECT MAX(age) FROM users);
SQL task: there is a table users with columns userid… - sobes.tech