141k views
1 vote
Which of the following queries does not correctly use aliases?

A) SELECT c.customer id, , name FROM invoice AS i JOIN customer AS c USING (customer id);
B) SELECT i.customer id, total, last name FROM invoice AS i JOIN customer AS c USING (customer id);
C) SELECT i.customer id, , name FROM invoice AS i JOIN customer AS c USING (customer id);
D) SELECT c.customer id, , name FROM invoice AS i JOIN customer AS c USING (customer id);

1 Answer

5 votes

Final answer:

Option C, 'SELECT i.customer id, , name FROM invoice AS i JOIN customer AS c USING (customer id)', is the query that does not correctly use aliases due to a syntax error involving an extra comma.

Step-by-step explanation:

The query that does not correctly use aliases is option C) SELECT i.customer id, , name FROM invoice AS i JOIN customer AS c USING (customer id). The problem with this query is that it contains a syntax error - there is a comma followed by a space without a column name between 'i.customer id' and 'name'. This would cause the SQL statement to fail. In SQL, aliases are used to give a table, or a column in a table, a temporary name that only lasts for the duration of the query. Aliases help to make queries easier to read and can be necessary when joining tables that have columns with the same name.

Correct alias usage is shown in option A and B, where 'AS c' and 'AS i' are used to alias the customer and invoice tables respectively. Option D has the same issue as C, the incorrect syntax with a double comma contributing to an improperly constructed SQL query.

User Gaurav Toshniwal
by
8.1k points