Part 3: SQL Query Interview Questions & Answers | How to find 1st, 2nd & Nth Highest Salary | 3 Ways

preview_player
Показать описание
SQL Query Interview Questions & Answers

Topics:
1) How to find 1st, 2nd & Nth Highest Salary | 3 Ways
2) How to find 1st, 2nd & Nth Highest Salary | 3 Different Ways (max(), limit & top )

Display the highest salary
Display the 2nd highest
Display the Nth highest salary

#########################
Udemy Courses:
#########################

Manual Testing+Agile with Jira Tool
****************************

Selenium with Java+Cucumber
********************************

Selenium with Python & PyTest
*************************

Selenium with python using Robot framework
*****************************

API Testing(Postman, RestAssured & SoapUI)
*******************************

Web & API Automation using Cypress with Javascript
***************************

Playwright with Javascript
**************************

Jmeter-Performance Testing
************************

SDET Essencials(Full Stack QA)
*************************

Appium-Mobile Automation Testing
*************************

Java Collections
*****************

Python Programming
*********************

Cucumber BDD Framework
***************************

Protractor with Javascript
***************************

####################################
Youtube Playlists:
####################################

Manual Testing & Agile
***********************

SQL
****

linux & Shell Scripting
**********************

Java
*****

Selenium With Java+Cucumber
********************************

Python
*******

Selenium With Python,Pytest&Behave
***************************************

Selenium With Python Using Robert Framework
(Web&API Testing)
*************************************************

API Testing (Postman,SoapUi,&Rest Assured)
**********************************************

Mobile App Testing Appium
****************************

Performance Testing Jmeter
*******************************

Maven,Jenkins,Git,Github,CI/CD
*******************************

SQL,DB Testing&ETL,Bigdata
*******************************

JavaScript Based Automation Tools
********************************

Selector Hub Tools
********************

GraphQL
********

Cypress API Testing
*******************

Cypress Web Testing
********************

Playwright with Javascipt
************************

#SQLInterviewQuestions
#SQLQueryTips
#SQLSalaryRanking
#SQLDataAnalysis
#SQLInterviewPrep
#SQLCodingChallenge
#SQLInterviewAnswers
#SQLQueryOptimization
#SQLWindowFunctions
#SQLAggregateFunctions
#SQLSubqueries
#SQLCommonTableExpressions
#SQLNestedQueries
#SQLSelfJoin
#SQLRankFunction
#SQLDenseRank
#SQLRowNumber
#SQLTopNRows
#SQLLimitOffset
#SQLInnerJoin
#SQLOuterJoin
#SQLCrossJoin
#SQLUnion
#SQLUnionAll
#SQLInterviewSkills
#SQLQueryChallenge
#SQLDatabaseManagement
#SQLInterviewGuidance
#SQLPerformanceTuning
#SQLDataManipulation
#SQLDataFiltering
#SQLDataSorting
#SQLDataGrouping
#SQLDataAggregation
#SQLWindowingFunctions
#SQLCTE
#SQLAdvancedQueries
#SQLDataAnalysisTechniques
#SQLCommonInterviewQuestions
#SQLCodingTips
#SQLPuzzleSolving
#SQLCareerPreparation
#SQLTechnicalInterviews
#SQLQueryChallenges
#SQLInterviewHelp
#SQLSalaryNegotiation
#SQLJobSearchTips
#SQLInterviewSuccess
#SQLQueryPerformance
#SQLCodingSolutions
Рекомендации по теме
Комментарии
Автор

SELECT salary from employee ORDER BY salary DESC LIMIT 1, 1;

will also give 28000/- i.e. 2nd highest salary.

if we want 3rd highest salary

SELECT salary from employee ORDER BY salary DESC LIMIT 2, 1; this will skip first 2 record and return 3rd record

rushabhsuranse
Автор

Wow! Awesome style of teaching! I am a newbie to sql and loving your tutorials.

RishiRap
Автор

Thanks a lot for the detailed explanation. Btw, I think the query need a small tweak on the subquery. Suppose we have one more employee with 28, 000 which is a very common scenario, the above query will fetch the same 28000 for 2nd and 3rd highest salaries. A distinct before salary in the subquery should resolve the duplicate salary issue. Once again Kudos to all your efforts in helping the testing community. 🙏

octotube
Автор

Thank you so much sir, now my concept is clear

arshadayyubbaghwan
Автор

Thank you very much Sir for your valuable video…

safrozeafroze
Автор

also use dense rank function and query be like
select dense_rank salary over(partition by salary from emploee order by salary)as rn salary where rn salary <2;

ncasmeer
Автор

You are excellent..the way you are explaining 👍

snigdha
Автор

using Top function u can also write a query like
select Top 1 salary from(select Top 2 salary from employee order by desc ) as max sal order by max sal ;

ncasmeer
Автор

How about this query? select * from employee order by salary Desc limit 1, 1;

rishudhamija
Автор

select min(salary) from (select salary from employee order by salary desc limit 2) salarylist ;
select min(salary) from (select salary from employee order by salary desc limit n) salarylist ;
will this also work for Q.22?
Is the above query proper one?
Simply curious to know Sir.

lightinlight
Автор

sir please stop highlighting or change the colour, we can't see the query

dreamershope
Автор

can't we use this sql query for second highest - select salary from employee order by salary desc limit(1, 1);

princedua
Автор

Thanks a
Sir, kindly request you that.. while creating maven project in my ecclipse(Luna) i got a error like ... Maven resources plugin 2.6 or one of its dependencies can't be resolved. Please give me advice how I can solve the problem.

tadavarthinaganavya
Автор

sir if I practice in ms SQL server management studio but at the time of interview I tell them MySQL function like limit then it is consider

johnfender
Автор

Sir can we use rownum in oracle for find nth highest salary

Deepak-mzif
Автор

Can we use
LIMIT 2, 1 for 2nd highest salary.
LIMIT 3, 1 for 3rd highest salary.

avik
Автор

After executing this query in Sql fiddle"Select Top 1 Salary from Employee order by Salary DESC;"

I am getting this Error"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1 Salary from Employee order by Salary DESC' at line 1"

saviv
Автор

Sir.. Query with Limit and top not execute in Oracle SQL developer...is it right....Plz rpl

riyarohit
Автор

Hi sir can you please share hr table in SQL in SQL tutorial comment section wrong link is give and can you please tell how to download the hr table into MySQL server

mohammedamaanhashmi
Автор

I am trying to purchase a course on your site but it's failing. I sent email. Please check.

youssoufcameroon