How do you select first_name and last_name from employees and alias the column last_name as surname in the result?

Study for the SQL Basics Test. Improve your knowledge with multiple choice questions and detailed explanations. Prepare effectively to master SQL concepts!

Multiple Choice

How do you select first_name and last_name from employees and alias the column last_name as surname in the result?

Explanation:
Aliasing lets you rename a column in the output. To rename the second column to surname, place AS followed by the new header after the column, so you’re clearly telling the database what to call that output column. The correct statement is: SELECT first_name, last_name AS surname FROM employees; This keeps first_name as is and makes the displayed column header for last_name become surname. The other forms don’t provide the explicit, portable aliasing: one would display the column as last_name without renaming it, another uses syntax (IN) that isn’t valid for aliasing, and the last omits AS (which some dialects tolerate but isn’t universally supported).

Aliasing lets you rename a column in the output. To rename the second column to surname, place AS followed by the new header after the column, so you’re clearly telling the database what to call that output column. The correct statement is: SELECT first_name, last_name AS surname FROM employees; This keeps first_name as is and makes the displayed column header for last_name become surname.

The other forms don’t provide the explicit, portable aliasing: one would display the column as last_name without renaming it, another uses syntax (IN) that isn’t valid for aliasing, and the last omits AS (which some dialects tolerate but isn’t universally supported).

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy