DS0-001 practice question 8 of 15

Which of the following statements contains an error?

Full set: 80 questions
Answer options
A: Select EmpId from employee where EmpId=90030
B: Select EmpId where EmpId=90030 and DeptId=34 Correct answer
C: Select* from employee where EmpId=90030
D: Select EmpId from employee
Correct Answer:
B. Select EmpId where EmpId=90030 and DeptId=34
Explanation

The SQL statement in option B, Select EmpId where EmpId=90030 and DeptId=34, contains a syntax error. A valid SELECT statement that retrieves data from a table must include a FROM clause to specify the source table. This statement is missing the FROM clause, making it syntactically incorrect and unexecutable by any standard SQL database management system. The basic structure of a query requires specifying what to select (SELECT), from where to select it (FROM), and optionally, the conditions for selection (WHERE).

Why Incorrect

A. This is a valid SQL query. It correctly uses the SELECT, FROM, and WHERE clauses to retrieve a specific employee's ID from the employee table.
C. This is a valid SQL query. The asterisk () is a wildcard that correctly selects all columns from the employee table for the specified EmpId.
D. This is a valid SQL query. It correctly uses the SELECT and FROM clauses to retrieve all values from the EmpId column in the employee table.

References

1. Ullman, J. D., & Widom, J. (n.d.). CS145 Introduction to Databases, Class Notes on SQL. Stanford University. Retrieved from https://infolab.stanford.edu/~ullman/fcdb/slides/slides-sql1.pdf. On page 4, the basic form of an SQL query is defined as SELECT FROM WHERE , explicitly showing the FROM clause as a required component.

2. PostgreSQL Documentation. (n.d.). 7.1. Overview. In PostgreSQL 16 Documentation. Retrieved from https://www.postgresql.org/docs/current/tutorial-select.html. The introductory example SELECT FROM weather; and subsequent explanations establish the FROM clause as fundamental for specifying the target table.

3. Stonebraker, M., & Hellerstein, J. (2005). 8. Relational Algebra and SQL. In 6.830 Database Systems, Fall 2005. Massachusetts Institute of Technology: MIT OpenCourseWare. Retrieved from https://ocw.mit.edu/courses/6-830-database-systems-fall-2005/resources/lec8/. Slide 20 presents the canonical SELECT-FROM-WHERE statement, reinforcing the necessity of the FROM clause.

Scroll to Top