I am learning SQL and was testing the with expression syntax when I ran into this error for my SQL query. I want to get the ids and names of all instructors from a university databse with the maximum salary. This database is from the book Database System Concepts by Silberschatz et al.
The schema of the instructor relation is instructor(ID, name, dept_name, salary) where the last attribute salary is a numeric type, MySQL Workbench is complaining that
Error Code: 1054. Unknown column 'max_salary.value' in 'where clause'
Here is my code
-- MySQL workbench complains with the above error!
with max_salary(value) as
(select max(salary)
from instructor)
select ID, name
from instructor
where max_salary.value = instructor.salary;
I know how to rewrite this without the with clause, as follows
but I was having trouble with the syntax of with for this particular problem.
-- This works!
select ID, name
from instructor
where instructor.salary = (select max(salary) from
instructor )
max_salarybeen declared in the with clause? It does exist.with max_salary(value) as (select max(salary) from instructor) select ID, name from instructor JOIN max_salary ON max_salary.value = instructor.salary;