Subquery Nested by WHERE

Function

Subqueries are nested in the WHERE clause, and the subquery result is used as the filtering condition.

Syntax

1
2
SELECT [ALL | DISTINCT] attr_expr_list FROM table_reference
  WHERE {col_name operator (sub_query) | [NOT] EXISTS sub_query};

Keyword

Precautions

The to-be-queried table must exist. If this statement is used to query a table that does not exist, an error is reported.

Example

To query the courseId of Biology from the course_info table, and then query the student name matched the courseId from the student_info table, run the following statement:

1
2
SELECT name FROM student_info
  WHERE courseId = (SELECT courseId FROM course_info WHERE courseName = 'Biology');