99.3k views
1 vote
Code example 4-1:

SELECT VendorName, InvoiceNumber
FROM Invoices JOIN Vendors
ON VendorID = VendorID

Which of the following is true with respect to code example 4-1?
1) The query results in an error because the keyword OUTER was not included.
2) The query results in an error because the keyword INNER was not included.
3) none of the above
4) The query generates an error because the table names were not included in the ON clause.

User Cuppy
by
7.9k points

1 Answer

2 votes

Final answer:

The query does not error due to a missing OUTER or INNER keyword, but it may error because the ON clause is ambiguous as it does not differentiate between the VendorID fields of the two tables.

Step-by-step explanation:

The query SELECT VendorName, InvoiceNumber FROM Invoices JOIN Vendors ON VendorID = VendorID does not necessarily result in an error. The absence of the OUTER or INNER keyword does not always lead to an error since JOIN is equivalent to INNER JOIN by default in many SQL databases. However, there is ambiguity in the ON clause as it does not properly qualify the VendorID fields from different tables. Usually, an alias or table name prefix is required to differentiate columns with the same name from different tables.

In this case, option 4 ('The query generates an error because the table names were not included in the ON clause') appears to be the correct option, assuming that the VendorID columns exist in both tables but are not distinctly referenced. This would likely cause an ambiguous column error in most SQL database systems.

User Jonny Phelps
by
8.1k points