CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Interview Success Kit - Get Success in Job Interviews Interview Success Kit - 30,000 Interview Que. & Ans.
Covers 30,000+ Interview Questions asked in actual MNC Interviews - all with model answers.

Sponsored Links

Interview Questions
Our Services

INTERVIEW QUESTIONS DATABASE MYSQL DETAILS
Question :
How to display nth highest record in a table for example?How to display 4th highest (salary) record from customer table?


Category MYSQL Interview Questions
Rating (3.0) By 31 users
Added on 7/25/2011
Views 2733
Rate it!


Answers:

Source: CoolInterview.com

Query: SELECT sal FROM `emp` order by sal desc limit (n-1),1If the question: "how to display 4th highest (salary) record from customer table."The query will SELECT sal FROM `emp` order by sal desc limit 3,1


Source: CoolInterview.com



Source: CoolInterview.com

select sal from emp order by descending where rownum=4
Source: CoolInterview.com



Posted by: Nibedita Swain

Contact Nibedita Swain Contact Nibedita Swain

Source: CoolInterview.com

There are two ways
- Using LIMIT clause
- Special SQL

Using LIMIT there are issues that if table has got same salary (field) value multiple times, but this will show you only one record, then you will not get to know that there are also others with same salary.

Another SQL Approach is -
-------------
select a.empid, a.salary from employees as a
where 2 =(select count(distinct b.salary) from employees as b
where b.salary >=a.salary)
---------------
this query will return you all the rows which comes under this criteria.
Source: CoolInterview.com



Posted by: kishor

Contact kishor Contact kishor

Source: CoolInterview.com

select * from TABLENAME where salary=(select salary from TABLENAME order by salary desc limit 4,1)


The following example is for the 6th highest :-
select * from TABLENAME where salary=(select salary from TABLENAME order by salary desc limit 6,1)


Source: CoolInterview.com



Posted by: Amit Shah

Contact Amit Shah Contact Amit Shah

Source: CoolInterview.com

select min(sal) from(select top(4)sal from tbsalary order by sal desc)as tbl
Source: CoolInterview.com



Posted by: Latika

Contact Latika Contact Latika

Source: CoolInterview.com

Amit Shah's answer works if there is only one record for top 3 salaries.

Including distinct command will work in all cases. Hence the query becomes,

SELECT * FROM `table_name` WHERE field_salary = (SELECT DISTINCT field_salary FROM `table_name` ORDER BY field_salary DESC LIMIT 4,1)
Source: CoolInterview.com



Posted by: Sriram Seshadri

Contact Sriram Seshadri Contact Sriram Seshadri

If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification Enter the above shown code: *
    Inform me about updated answers to this question

    Related Questions
    View Answer

    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

    View ALL MYSQL Interview Questions & Answers

    User Options
    India News Network

    Latest 20 Questions
    Agreement of Trial Balance is not a ________ proof of accuracy. a) Submissive b) Inclusive c) Exhaustive d) Conclusive
    _________ is prepared to ascertain the arithmetical accuracy of posting and balancing a) Cash Book b) Journal c) Trial Balance d) Bank Reconciliation Statement
    Closing stock in the trial balance implies that. a) It is already adjusted in the opening stock b) It is adjusted in Sales A/c. c) It is adjusted in the Purchase A/c. d) None of these
    Trial Balance creates ________ accuracy. a) Principle b) Arithmetical c) Clerical d) None
    Which of the following in Trial Balance is contradictory to each other? a) Inventory and Drawings b) Sales and Purchase Return c) Carriage Inward and Outward d) Trade Receivable and Liability
    Which of the following is not a process in the preparation of a Trial Balance? a) Recording b) Summarizing c) Classifying d) Interpretation
    A list which contains balances of accounts to know whether the debit and credit balances are matched. a) Balance Sheet b) Day Book c) Journal d) Trial Baalnce
    Balances of the Accounts are transferred to: a) Trial Balance b) Trading Account c) Profit & Loss Account d) Balance Sheet
    Trial Balance is prepared on : a) End of the year b) A particular date c) For the period ending_______ d) Both "a" and "b"
    A Trial Balance contains the balances of: a) Only personal and real accounts b) Only real and nominal accounts c) Only nominal and personal accounts d) All accounts
    Trial Balance under balance method is known as: a) Gross Trial Balance b) Net Trial Balance c) Simple Trial Balance d) Trial Balance Appropriation
    Difference of totals of both debit and credit side of trial balance is transferred to: a) Trading Account b) Suspense Account c) Difference Account d) Miscellaneous Account
    The trial balance of M/S RAM & Co. shows closing stock of Rs. 30,000. It will be recorded in: a) Trading Account b) Profit and Loss Account c) Balance Sheet d) Both (a) and (c)
    The preparation of trial balance is for: a) Locating errors of commission b) Locating errors of principle c) Locating clerical errors d) All of the above
    Trial Balance is a: a) Statement b) Account c) Summary d) Ledger
    Methods of preparation of Trial Balance are: a) Balance Method b) Total Method c) Total and Balance Method d) All of these
    What is Constructive Dividend in Taxation?
    What is Consolidated tax return in Taxation?
    What is Conduit Approach in Taxation?
    What is Competent Authority (CA) in Taxation?



    Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

    Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

    MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
    MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

    GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

    IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
    IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

    SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
    SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




    Copyright ©2003-2016 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions



    Cache = 0.683594 Seconds