SQL Query Interview Questions in MCQ format

Which of the following is a correct SQL query?

a) SELECT emp_name, salary FROM Employees WHERE salary>10000 AND <20000;
b) SELECT emp_name, salary FROM Employees WHERE salary>10000 AND WHERE salary<20000;
c) SELECT emp_name, salary FROM Employees WHERE salary>10000 AND salary<20000; d) None of these.

Answer: c

Write a query to retrieve the employee’s first name and last name and concatenate them in a single column?

a) SELECT CONCAT (emp_fname, ‘ ’, emp_lname) AS Fullname FROM Employees;
b) SELECT (emp_fname, ‘ ’, emp_lname) AS Fullname FROM Employees;
c) SELECT emp_fname, emp_lname CONCAT AS Fullname FROM Employees;
d) SELECT FROM Employees CONCAT (emp_fname, emp_name) AS Fullname;

Answer: a

In an Employees table where the employee with the highest salary is at the top, consider the following query

SELECT TOP 1 salary
FROM(
SELECT TOP 3 salary
FROM Employees
ORDER BY salary ASC) AS employee
ORDER BY salary DSC;
The above SQL query will return which one of the following

a) The highest salary.
b) The second highest salary.
c) The third highest salary.
d) The top three highest salary.

Answer: c

First, the sub query will return the top three records in an ascending order and the outer query will return the first record which is actually the third highest salary.

If we don’t specify ASC or DSC after the ORDER BY command, which of the following is used by default?

a) ASC
b) DSC
c) Nothing will be done.
d) None of the above.

Answer: a

ORDER BY command sorts the result set in an ascending order by default.

Example

SELECT * FROM Employees
ORDER BY Country;

The above SQL statement will sort the records in an ascending order.

Select all records from the Employees table where the Phone_number is empty. SELECT * FROM Employees WHERE _________

a) Phone_number IS NULL.
b) Phone_number IS EMPTY.
c) Phone_number IS NOT TRUE
d) None of the above.

Answer: a

A field with a NULL value is one that has been left blank during record insertion.
Post your comment

    Discussion

  • RE: SQL Query Interview Questions in MCQ format -SQL query (09/10/22)
  • Good questions

    Post more questions