124k views
4 votes
Which of the following queries does not correctly use aliases?

a) SELECT i.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

3 votes

Final answer:

The query that does not correctly use aliases is option c) due to a syntax error with two commas and no specified table alias for the name column.option c).

Step-by-step explanation:

The query that does not correctly use aliases is option c). In this query, there seem to be two commas before the name field, which appears to be syntax error as there is no column name provided between them. Moreover, the name column doesn't have a specified alias, which would cause an error if both the invoice and customer tables contain a column with this name, as the SQL engine would not be able to resolve the ambiguity. All other options correctly use the alias notation, provided that the tables invoice and customer contain the columns referenced, and there were no actual typos as part of the SQL code being asked about.

Aliases are used in SQL queries to give tables or columns temporary names, making the query more readable and concise. In the given options, option c) SELECT i.customer_id, , name FROM invoice AS i JOIN customer AS c USING (customer_id) does not correctly use aliases.

The correct syntax to use alias in this query is:

SELECT i.customer_id, c.name FROM invoice AS i JOIN customer AS c USING (customer_id);

User Manu Mathew
by
8.3k points