102-500 practice question 3 of 30

Which of the following SQL statements will select the fields name and address from the contacts table?

Full set: 233 questions
Answer options
A: SELECT (name, address) FROM contacts;
B: SELECT (name address) FROM contacts;
C: SELECT name, address FROM contacts; Correct answer
D: SELECT name address FROM contacts;
Correct Answer:
C. SELECT name, address FROM contacts;
Explanation

The standard SQL syntax for selecting specific columns from a table is SELECT column1, column2, ... FROM tablename;. The column names must be separated by a comma. Parentheses are not used to enclose the column list in a simple SELECT statement, and omitting the comma between column names results in a syntax error.

Why Incorrect

A. SELECT (name, address) FROM contacts; is incorrect because parentheses are not used to group the column list in this context.
B. SELECT (name address) FROM contacts; is incorrect due to both the use of parentheses and the missing comma between field names.
D. SELECT name address FROM contacts; is incorrect because it lacks the required comma separator between the name and address fields.

References

1. PostgreSQL 14 Documentation, "Chapter 7. Queries", Section 7.3 "The Target List". It states, "The simplest kind of target list is ... A second kind of target list consists of a comma-separated list of expressions".

2. MySQL 8.0 Reference Manual, "13.2.13 SELECT Statement". The syntax shown is SELECT selectexpr [, selectexpr] ... FROM tablereferences. This explicitly shows the comma-separated list of expressions (columns).

3. Ramakrishnan, R., & Gehrke, J. (2003). Database Management Systems (3rd ed.). McGraw-Hill. Chapter 5, "SQL: The Query Language", Section 5.2 "The Basic Form of an SQL Query", page 143, illustrates the SELECT [DISTINCT] select-list FROM from-list WHERE qualification syntax, where select-list is a list of column names separated by commas.

Scroll to Top