Knowee
Questions
Features
Study Tools

This task concerns the following tables:PersonsidnameaddressageeyeColorgenderWrite a query that returns the name of all persons that are at least as old as everybody else.TipRecall the logic recap: FOR ALL X can be expressed by NOT EXISTS NOT X

Question

This task concerns the following tables:PersonsidnameaddressageeyeColorgenderWrite a query that returns the name of all persons that are at least as old as everybody else.TipRecall the logic recap: FOR ALL X can be expressed by NOT EXISTS NOT X

🧐 Not the exact question you are looking for?Go ask a question

Solution

To answer your question, you can use a subquery to find the maximum age, and then use this subquery in the WHERE clause of your main query. Here is the SQL query:

SELECT name
FROM Persons
WHERE age >= (SELECT MAX(age) FROM Persons);

This query works as follows:

  1. The subquery (SELECT MAX(age) FROM Persons) finds the maximum age of all persons in the table.
  2. The main query then selects the names of all persons whose age is greater than or equal to this maximum age.

This will return the names of the oldest persons in the table.

This problem has been solved

Similar Questions

This task concerns the following tables:PersonsidnameaddressageeyeColorgenderKnowsidpersonA_id → PersonspersonB_id → PersonsThe semantics of the Knows table is that personA knows personB.Write a query that returns the name of all persons that are more than 5 years older than everybody they know.

This task concerns the following tables:PersonsidnameaddressageeyeColorgenderLikesidpersonA_id → PersonspersonB_id → PersonsThe semantics of the Likes table is that personA likes personB.Use a LEFT JOIN to write a query that returns the name of all people that do not like anyone.ImportantYou can test whether an attribute is null by attribute IS NULL

This task concerns the following tables:PersonsidnameaddressageeyeColorgenderLikesidpersonA_id → PersonspersonB_id → PersonsKnowsidpersonA_id → PersonspersonB_id → PersonsThe semantics of the Likes table is that personA likes personB.The semantics of the Knows table is that personA knows personB.Write a query that returns the name of all persons that like everyone they know.

This task concerns the following tables:PersonsidnameaddressageeyeColorgenderKnowsidpersonA_id → PersonspersonB_id → PersonsThe semantics of the Knows table is that the person referenced by personA_id knows the person referenced by personB_id.TakesClassesidperson_id → Personsclass_id → ClassesThe semantics of the TakesClasses table is that person referenced by person_id takes the class referenced by class_id.Use NOT IN to write a query that returns the name of all persons that do not know anyone who takes classes.

Persons who like someone with blue eyesThis task concerns the following tables:PersonsidnameaddressageeyeColorgenderLikesidpersonA_id → PersonspersonB_id → PersonsThe semantics of the Likes table is that personA likes personB.Write a query that returns the name of all persons that like someone with blue eyes. Eliminate duplicates from your query result.

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.