185k views
0 votes
You are querying a database that contains data about music. You are only interested in data related to the jazz musician Miles Davis. The names of the musicians are listed in the composer column.

You write the following SQL query, but it is incorrect. What is wrong with the query?
SELECT *
FROM Track
WHERE composer = Miles Davis

-Line 3 should be rewritten as WHERE composer is Miles Davis.
-Composer in line 3 should be capitalized.
-Miles Davis should be in double quotation marks.
-SELECT, FROM, and WHERE should not be capitalized.

1 Answer

2 votes

Final answer:

The error in the SQL query is the absence of single quotes around the string literal 'Miles Davis'. SQL syntax is not case-sensitive for keywords, so capitalization of SELECT, FROM, and WHERE is not an issue.

Step-by-step explanation:

The issue with the SQL query is that the name Miles Davis should be in single quotes because it is a string literal. The corrected query should read as follows:

SELECT * FROM Track WHERE composer = 'Miles Davis'

SQL keywords such as SELECT, FROM, and WHERE are not case-sensitive, so their capitalization is not an error. Additionally, SQL uses single quotes for string literals, not double quotes. The suggestion to use IS instead of = is incorrect, as IS is used for comparing against NULL values, not strings.

The query in question is incorrect because it does not correctly specify the condition to filter the data related to Miles Davis. The correct syntax to compare strings in SQL is to use single quotation marks around the value being compared. Therefore, the correct query should be:

SELECT * FROM Track WHERE composer = 'Miles Davis'

Additionally, it is worth noting that SQL is case-insensitive, so whether the column name 'composer' is capitalized or not does not affect the functionality of the query.

User KC Baltz
by
8.3k points