SQL Server interview question :- Select record with the second lowest value from the below customer table?
Shivprasad Koirala
There is another query to get the second lowest value from this table
No it is not wrong it is giving the exact result.Try again..............
There is something wrong in the second query. I executed the same did not give me exact results.
My 500 .NET interview questions and answers
We can get the second lowest value from the above table
Answer:
Below is a simple customer table with 3 fields code , name and amount. Can you select the customer with second lowest amount. This is one of the favorite questions which is asked to test your SQL Server skills.
Below is the answer. It can be accomplished by using sub queries. First select the min and then get all records which are more than the min and select top 1 from the same. Below goes the query.
select top 1 * from tbl_Customer touter where touter.Amount > (SELECT min(tinner.Amount) FROM [Customer].[dbo].[tbl_Customer] as tinner) order by touter.Amount asc
Some time interviewers can trick you questions like select the second top. In the subquery we just need to change the same to max.
Get 200 SQL Server Interview questions and answers or .NET Interview questions and answers