LFCS · Question #241
Which of the following SQL statements will select the fields name and address from the contacts table?
The correct answer is C. SELECT name, address FROM contacts. The correct SQL statement to select multiple columns requires listing each column name separated by a comma after the SELECT keyword.
Question
Options
- ASELECT (name, address) FROM contacts;
- BSELECT (name address) FROM contacts;
- CSELECT name, address FROM contacts;
- DSELECT name address FROM contacts;
How the community answered
(25 responses)- B8% (2)
- C88% (22)
- D4% (1)
Why each option
The correct SQL statement to select multiple columns requires listing each column name separated by a comma after the SELECT keyword.
Parentheses are not used to enclose a list of column names in a standard SQL SELECT statement, making the syntax incorrect.
Parentheses are incorrectly used, and column names must be separated by commas, not spaces, in a standard SQL SELECT statement.
The `SELECT name, address FROM contacts;` statement correctly uses commas to separate multiple column names, which is the standard SQL syntax for retrieving specific columns from a table. This syntax instructs the database to return values from both the 'name' and 'address' columns for all rows in the 'contacts' table.
Column names must be separated by commas when selecting multiple columns; simply using a space is not valid SQL syntax for this purpose.
Concept tested: SQL SELECT statement syntax for multiple columns
Source: https://dev.mysql.com/doc/refman/8.0/en/select.html
Topics
Community Discussion
No community discussion yet for this question.