Question

In: Computer Science

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

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

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

ID is the primary key

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

I know how to do it if I only needed to report the second highest salary, but I am having trouble getting it with the corresponding name 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 without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'database.instructor.ID'; this is incompatible with sql_mode=only_full_group_by"


Any help is appreciated!

Solutions

Expert Solution

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

Is right and it works properly but when we execute that code it show an error message that is "In aggregated query without GROUP BY, expression #1 of SELECT list contains non aggregated column 'database.instructor.ID'; this is incompatible with sql_mode=only_full_group_by" this means we cannot execute two attributes simultaneously without using GROUP BY command because this is how the configuration is done in mysql so if we want to change the configuration file than we have to write some code in it to resolve this error that is :-

code ---

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

This will change the global sql mode that is set to Group by to sql_mode so that we can execute all the commands.

Config File: /etc/mysql/my.cnf

Variable name : sql_mode OR sql-mode

you can change it directly if you are using XAMPP server or phpMyAdmin that's if you are using phpMyAdmin then change the "sql_mode" setting as mentioned the in below screenshot.

Edit "sql mode" variable and remove the "ONLY_FULL_GROUP_BY" text from the value.

HOPE YOU GOT IT.


Related Solutions

Use the method of reduction of order to find a second solution y2 of the given...
Use the method of reduction of order to find a second solution y2 of the given differential equation such that {y1, y2} is a fundamental set of solutions on the given interval. t2y′′ +2ty′ −2y=0, t > 0, y1(t)=t (a) Verify that the two solutions that you have obtained are linearly independent. (b) Let y(1) = y0, y′(1) = v0. Solve the initial value problem. What is the longest interval on which the initial value problem is certain to have...
Assuming that x>0, use the method of reduction of order to find a second solution to...
Assuming that x>0, use the method of reduction of order to find a second solution to x^2y''−3xy'+4y=0 Given y1(x)=x^2
Use the graph to find the limit L (if it exists). If the limit does not...
Use the graph to find the limit L (if it exists). If the limit does not exist, explain why. (If an answer does not exist, enter DNE.) h(x) = -x/2 + x2 (a) lim x→2 h(x) L = (Select One) The limit does not exist at x = 2 because the function is not continuous at any x value. The limit does not exist at x = 2 because the function approaches different values from the left and right side...
Use ‘Reduction of Order’ to find a second solution y2 to the given ODEs: (a) y′′+2y′+y=0,...
Use ‘Reduction of Order’ to find a second solution y2 to the given ODEs: (a) y′′+2y′+y=0, y1 =xe−x (b) y′′+9y=0, y1 =sin3x (c) x2y′′+2xy′−6y=0, y1 =x2 (d) xy′′ +y′ =0, y1 =lnx
Consider the homogeneous second order equation y′′+p(x)y′+q(x)y=0. Using the Wronskian, find functions p(x) and q(x) such...
Consider the homogeneous second order equation y′′+p(x)y′+q(x)y=0. Using the Wronskian, find functions p(x) and q(x) such that the differential equation has solutions sinx and 1+cosx. Finally, find a homogeneous third order differential equation with constant coefficients where sinx and 1+cosx are solutions.
Limit order book Below you can find order information received by the Exchange for stock ABC...
Limit order book Below you can find order information received by the Exchange for stock ABC from 9am to 10am. Please construct the limit order book for these orders. The format of limit order book is provided below and feel free to insert more rows if needed. For the orders which can be executed or partially executed, please list the price executed and how many shares being executed. Please show the final limit order book and final market bid and...
There are 4 conditions that must be true in order to use the Central Limit theorem.
There are 4 conditions that must be true in order to use the Central Limit theorem. 1) We must have a simple random sample (SRS); 2) the sample size must be less than 10% of the population; 3) the observations must be independent; and 4) the sample size must be large enough so that both np > 10 and n(1 - p) >10, in which the true proportion (or probability) possessing the attribute of interest is p. Then the Central...
There are 4 conditions that must be true in order to use the Central Limit theorem.
Part 3: The Central Limit Theorem for a Sample ProportionThere are 4 conditions that must be true in order to use the Central Limit theorem. 1) We must have a simple random sample (SRS); 2) the sample size must be less than 10% of the population; 3) the observations must be independent; and 4) the sample size must be large enough so that both np > 10 and n(1 - p) >10, in which the true proportion (or probability) possessing...
There are 4 conditions that must be true in order to use the Central Limit theorem....
There are 4 conditions that must be true in order to use the Central Limit theorem. 1) We must have a simple random sample (SRS); 2) the sample size must be less than 10% of the population; 3) the observations must be independent; and 4) the sample size must be large enough so that both np > 10 and n(1 - p) >10, in which the true proportion (or probability) possessing the attribute of interest is p. Then the Central...
Find the first-order and second-order partial derivatives of the following functions: (x,y) =x2y3
Find the first-order and second-order partial derivatives of the following functions: (x,y) =x2y3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT