Given the table:
Products(id, price)
How do I write a sql query to return all the productus with the Nth highest price (can be more than one with that proce)
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is the most generic I can make this, but it still uses TOP where some RDBMS use LIMIT, so you may need to make slight modificiation.
Other dialects that allow row_number would likely make better options than my nested sub-queries.
EDIT : Typed MAX, meant MIN
EDIT : Someone suggested I give an example using windowing functions…
Or use DENSE_RANK, depending on the behavior you want.
Note : Check your RDBMS for use of windowed functions. Not all are created equal.