tag:blogger.com,1999:blog-694855878384792308.post5096633160938616466..comments2024-03-21T06:26:49.387-07:00Comments on Java67: Second Highest Salary in MySQL and SQL Server - LeetCode Solutionjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger49125tag:blogger.com,1999:blog-694855878384792308.post-73225814276038685922023-03-31T22:26:16.170-07:002023-03-31T22:26:16.170-07:00select top 1 salary from Mahesh where salary in
(s...select top 1 salary from Mahesh where salary in<br />(select distinct top 3 salary from Mahesh order by salary desc) <br />order by salary Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-35612398878198701262022-09-01T07:07:48.250-07:002022-09-01T07:07:48.250-07:00What is returning in current code? I believe it wi...What is returning in current code? I believe it will return null if table is empty and the one record if table just have one recordjavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-38526796996331616052022-08-29T21:37:22.133-07:002022-08-29T21:37:22.133-07:00What is the table has only one record? How to retu...What is the table has only one record? How to return null in that case.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-11673392418238956182022-03-24T02:44:28.013-07:002022-03-24T02:44:28.013-07:00This query shown all employee list of getting 2nd ...This query shown all employee list of getting 2nd highest salary.<br /><br />select * from master_salary where emp_salary = (select `emp_salary` from `master_salary` group by emp_salary limit 1,1);Tapas Talukderhttps://www.blogger.com/profile/12055150053666674904noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-23765590086333563212022-01-25T05:47:38.080-08:002022-01-25T05:47:38.080-08:00How to use in Joins
display max(sala) based on de...How to use in Joins <br />display max(sala) based on depart wise<br />dep_no, de_name, max(sal)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-2533680133048626222020-10-31T19:55:19.711-07:002020-10-31T19:55:19.711-07:00If criterion is to choose unique salary then just ...If criterion is to choose unique salary then just use distinct to filter out duplicate salaries like <br />Select min(salary) from ( select top2 distinct salary from employee order by desc ) as salay;javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-25039949617339591292020-10-29T08:56:50.303-07:002020-10-29T08:56:50.303-07:00what if first twosalary is same then this qunry wo...what if first twosalary is same then this qunry work ?Abhihttps://www.blogger.com/profile/06239254896478441388noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-78291616461086306952020-08-15T21:35:00.025-07:002020-08-15T21:35:00.025-07:00Hello reehant, what error you are getting and what...Hello reehant, what error you are getting and what is your SQL query, can you post it here please? I have showed <a href="https://www.java67.com/2020/05/nth-highest-salary-in-mysql-and-sql-server-example.html" rel="nofollow">how to find Nth highest salary</a> on this article, you may want to check. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-73570972483968654302020-08-07T20:02:44.810-07:002020-08-07T20:02:44.810-07:00how to modify it for Nth highest? Tried but gettin...how to modify it for Nth highest? Tried but getting error.reehanthttps://www.blogger.com/profile/15439825481059245207noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-24330695663466660372020-07-18T11:30:16.847-07:002020-07-18T11:30:16.847-07:00Use the -- distinct(salary)Use the -- distinct(salary)Anonymoushttps://www.blogger.com/profile/14831024808162488369noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-29817892904803628842020-06-26T23:31:49.339-07:002020-06-26T23:31:49.339-07:00This is as easy as it can be but it will not work ...This is as easy as it can be but it will not work in all database and probably not on interviews, where you are most likely be asked about window function and co-related subquery. It's good to know those techniques as well. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-20223527950889573692020-06-26T01:42:43.809-07:002020-06-26T01:42:43.809-07:00from the above query it will provide the result of...from the above query it will provide the result of highest salary of employee instead<br /> of second highest salaryAnonymoushttps://www.blogger.com/profile/12950726050987425094noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-34803239190694777452020-06-18T23:56:20.915-07:002020-06-18T23:56:20.915-07:00Try This:
select salary from employee order by sal...Try This:<br />select salary from employee order by salary desc limit 1 offset 1;<br />Rahul Beledehttps://www.blogger.com/profile/04138589474277527818noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-31432080796204466942020-05-16T08:07:22.008-07:002020-05-16T08:07:22.008-07:00Thanks, helpful! You saved me some headache.Thanks, helpful! You saved me some headache.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-38811339839241288272020-04-30T05:23:13.186-07:002020-04-30T05:23:13.186-07:00May be you can try like this:
select e.*, DATEADD(...May be you can try like this:<br />select e.*, DATEADD(month,3,'2008-02-26')AS DateAdd from Employee e where e.Sal='30000'javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-84268603025291712022020-04-30T05:22:53.771-07:002020-04-30T05:22:53.771-07:00select e.*, DATEADD(month,3,'2008-02-26')A...select e.*, DATEADD(month,3,'2008-02-26')AS DateAdd from Employee e where e.Sal='30000'javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-48799253529452083202020-04-29T12:21:29.210-07:002020-04-29T12:21:29.210-07:00/*Add 3 months to the employee who joined on 26th .../*Add 3 months to the employee who joined on 26th feb 2008 and whose sal is 30000*/<br />select * from Employee<br />where Sal='30000'<br /><br />select DATEADD(month,3,'2008-02-26')AS DateAdd;<br />Q)how do I add this two statements?Anonymoushttps://www.blogger.com/profile/06713515140606112578noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-48693091744642782972020-04-03T05:31:42.896-07:002020-04-03T05:31:42.896-07:00just use that salary to get all employees with tha...just use that salary to get all employees with that salaryjavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-9677419146162821022020-04-02T20:57:01.237-07:002020-04-02T20:57:01.237-07:00if the second maximum salary has two rows say ther...if the second maximum salary has two rows say there are two employees having 200<br />how can i display the records of both the rows having the same second highest salaryAnonymoushttps://www.blogger.com/profile/07328319045343165226noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-50864497334101987502019-12-27T05:37:39.553-08:002019-12-27T05:37:39.553-08:00Not valid order by clause in subquery. Not valid order by clause in subquery. Tamilselvanhttps://www.blogger.com/profile/00475191757589073393noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-19528364479416537832019-11-07T10:54:26.629-08:002019-11-07T10:54:26.629-08:00Select top 1 a.* from (select Distinct top 2 Salar...Select top 1 a.* from (select Distinct top 2 Salary as slry from employee order by desc)a<br />order by a.slry ascAnonymoushttps://www.blogger.com/profile/12895599288939633600noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-38086307982380122622019-10-14T23:40:19.919-07:002019-10-14T23:40:19.919-07:00Write SQL query to get third highest salary from E...Write SQL query to get third highest salary from Employee table without using nested query?Anonymoushttps://www.blogger.com/profile/09497061137466368651noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-61545709738805472282019-09-14T01:10:07.663-07:002019-09-14T01:10:07.663-07:00select *
from employees
order by ...select * <br />from employees<br />order by salary desc<br />limit 1,1;siddhu salvihttps://www.blogger.com/profile/13540835537227330999noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-40530407522271730672019-06-13T06:26:36.931-07:002019-06-13T06:26:36.931-07:00Not working on which database? what output/error y...Not working on which database? what output/error you are getting?javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-62148476664846777922019-06-12T18:29:49.764-07:002019-06-12T18:29:49.764-07:00SQL> select max(sal) from emp
2 where sal ...SQL> select max(sal) from emp<br /> 2 where sal > ( select max(sal) from emp where sal > (select max(sal) from emp));<br /><br /> MAX(SAL)<br />----------<br /><br />not workingsubuhttps://www.blogger.com/profile/00363395950628091595noreply@blogger.com