Roger is the HR Manager of Neon Inc. He wants to generate a report of all the employees working in
Department ID 30 from the Emp table on the following attributes:
Fname
Lname
Salary
All the records should be sorted in ascending order of the Lname attribute. Which of the following
queries will he use to get the required output?
A.
SELECT Fname Lname Salary FROM Emp WHERE DeptId=30 ORDER BY Lname
B.
SELECT Fname, Lname, Salary FROM Emp ORDER BY Lname WHERE DeptId=30
C.
SELECT Fname Lname Salary FROM Emp ORDER BY Lname WHERE DeptId=30
D.
SELECT Fname, Lname, Salary FROM Emp WHERE DeptId=30 ORDER BY Lname
Explanation:
The first part of the query, i.e. SELECT Fname, Lname, Salary selects the Fname, Lname, and Salary
columns (attributes). The second part, i.e. FROM Emp selects the Emp table, and the third part, i.e.
WHERE DeptId=30 specifies the condition that DeptId is 30. The ORDER BY clause is used to sort the
name in ascending order of Lname.In the ORDER BY clause, ascending is the default order.
Therefore, if no order is given, the column is sorted in ascending order.
Answer C is incorrect. The first part, i.e. SELECT Fname Lname Salary has an error, as each column
name must be separated by a comma, and the ORDER BY clause should be after the WHERE clause
and not before it.
Answer B is incorrect. The ORDER BY clause should be used after the WHERE clause and not before
it.
Answer A is incorrect. The first part of the query, i.e. SELECT Fname Lname Salary is erroneous, as
each column name must be separated by a comma.