select nested query code example
Example: sql nested select
SELECT * FROM students WHERE notes > ( SELECT AVG(notes) FROM students );
SELECT * FROM students WHERE class_id = (
SELECT id FROM classes WHERE number_of_students = (
SELECT MAX(number_of_students) FROM classes
)
);
SELECT subject, MAX(salary_by_subject.avg_salary) AS max_salary
FROM (
SELECT subject, AVG(monthly_salary) AS avg_salary
FROM teachers
GROUP BY subject
) salary_by_subject;