Oracle Database Sql Certified Associate · Free Practice Question Medium

Question 16

View and examine the following SQL exhibits.

Exhibit: 1


Exhibit: 2


Indicate what is true about these queries.

  • A

    The second statement returns a syntax error.

  • B

    The two statements can be made to produce identical results by adding a column alias for the salary column in the second SQL statement.

  • C

    The two statements produce identical results.

  • D

    There is no need to specify DESC because the results are sorted in descending order by default.

Reveal correct answer

Correct answer: C

Explanation

Correct answer: The two statements produce identical results.


Analyze the two SQL queries carefully:

Exhibit 1:

  • Orders the result by the salary column in descending order.

Exhibit 2:

  • Orders the result by the second column in the SELECT list, which is salary.

  • ORDER BY 2 means order by the second selected column.

  • Adding DESC makes it descending order.

Now, let's examine the statements:

  1. The two statements produce identical results.
    True

  • Both sort by the salary column descending.

  • ORDER BY salary DESC and ORDER BY 2 DESC are equivalent here.

  1. The second statement returns a syntax error.
    False

  • Ordering by column position is valid in SQL.

  1. There is no need to specify DESC because the results are sorted in descending order by default.
    False

  • Default order is ascending, so DESC is necessary to sort descending.

  1. The two statements can be made to produce identical results by adding a column alias for the salary column in the second SQL statement.
    False

  • Adding an alias is unnecessary since ordering by column position already works.

A. The second statement does not return a syntax error. Both SQL statements are valid and will execute without any syntax errors.

B. Adding a column alias for the salary column in the second SQL statement will not make the two statements produce identical results. The column alias does not affect the sorting order of the results.

C. The two statements produce identical results because they both retrieve data from the EMPLOYEES table and sort the results by the SALARY column in descending order.

D. There is no need to specify DESC in the ORDER BY clause because the results are sorted in ascending order by default. If you want to sort in descending order, you need to explicitly specify DESC in the ORDER BY clause.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need