Select Top Candidate

Here is an interview questions that I have been asked. Given an employee table with a salary column, what SQL statement would give you the top five earning employees?

But before you select the SQL statement you have to select the database implementation. Here is how you might do it in Oracle:

SELECT name FROM employees WHERE ROWNUM < = 5;

In Microsoft SQL Server:

SELECT TOP 10 name FROM employees;

In MySQL:

SELECT name FROM employees LIMIT 10;

This is almost a trick question especially when the person asking the question might only know one of the many possible answers. Now, if the interviewer is reading the answer written along with the questions they might not understand that there is more than one way to do it. If they are asking questions where they don’t know the answer you might not want to work there, unless you are seriously strapped for cash. So remember, when you are looking for employment you should be looking for the top work environment.