query to get maximum amount
Sukesh Marla
HOW TO WRITE SQL QUERY 2ND HIGHEST SALARY USING SELF JOIN
SELECT E1.SALARY FROM salary E1 WHERE 1= (SELECT COUNT(distinct (E2.salary)) FROM salary E2 WHERE E2.salary >=E1.salary)
SELECT E1.SALARY FROM Employee E1 WHERE 2-1 = (SELECT COUNT(distinct (E2.salary)) FROM Employee E2 WHERE E2.salary < E1.salary)
SELECT E1.SALARY FROM Employee E1 WHERE 1-1 = (SELECT COUNT(distinct (E2.salary)) FROM Employee E2 WHERE E2.salary > E1.salary)
For SQL SERVER INTERVIEW QUERIES QUESTION FOLLOW THE BELOW LINKMORE THAN 100 MS SQL SERVER INTERVIEW QUERIES WITH EXAMPLEhttp://www.interviewquestionspdf.com/2014/07/sql-queries-interview-questions-answers.html
Declare @MaxValue int Select @MaxValue=(case when @MaxValue>Amount then @MaxValue else Amount end) From T1 Select @Maxvalue
Declare @MaxValue int Select @MaxValue=Amount From T1 Group by Amount Select @MaxValue
SELECT T11.Id, T11.Amount as MaxAmount FROM T1 AS T11 left outER JOIN T1 AS T12 ON T11.Amount < T12.Amount GROUP BY T11.Amount, T11.Id having COUNT(T12.Amount)=0