Which statement identifies the syntax error in the following query: select Lastname, Firstname from charity.donors where Donation > 1000 and Lastname not in select Lastname from charity.current?

Get ready for the SAS Advanced Programming Certification Exam. Use multiple choice questions and flashcards, with detailed explanations. Ensure success in your exam and enhance your SAS skills!

The correct choice identifies that parentheses are required around the subquery in the SQL statement. In SQL syntax, whenever a subquery is used as part of a condition, especially with operators such as IN, NOT IN, EXISTS, or ANY, the subquery must be enclosed in parentheses.

In the example provided, the statement intends to filter out Lastnames from the charity.current table in the main query. However, because the subquery is not enclosed in parentheses, it results in a syntax error. Correctly structuring the query would look like this:


SELECT Lastname, Firstname

FROM charity.donors

WHERE Donation > 1000

AND Lastname NOT IN (SELECT Lastname FROM charity.current);

This adjustment ensures that the database engine correctly interprets the subquery as a distinct component of the condition being evaluated.

The other options do not address the fundamental issue presented by the original query concerning the lack of parentheses. For example, semicolons typically denote the end of a SQL statement rather than fitting within the query clause, and there’s no requirement for the subquery to be in a HAVING clause nor to reference the same table as the outer query in this context.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy