Q) Find the instructor earning the second highest salary. (Don’t use ORDER BY and LIMIT in...

70.2K

Verified Solution

Question

Programming

Q) Find the instructor earning the second highest salary. (Don’tuse ORDER BY and LIMIT in your solution.) in MySQL

here is the table I am using named Instructor with the following 4attributes:
Instructor(ID, name, dept_name, salary)

ID is the primary key

I am supposed to report the answer with the name, ID and salary ofthe second highest salaried instructor.

I know how to do it if I only needed to report the second highestsalary, but I am having trouble getting it with the correspondingname and id as well. This is what I am trying:

Select ID, name, max(salary) as salary
From instructor
Where salary < (select max(salary)
              From instructor);


but it is saying \"Error Code: 1140. In aggregated query withoutGROUP BY, expression #1 of SELECT list contains nonaggregatedcolumn 'database.instructor.ID'; this is incompatible withsql_mode=only_full_group_by\"


Any help is appreciated!

Answer & Explanation Solved by verified expert
4.2 Ratings (879 Votes)
ans Select ID name maxsalary as salary From instructorWhere salary select maxsalary From instructorIs right and it works properly but when we execute that code itshow an error message that is In aggregated query    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students