Subqueries - Subqueries

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Subqueries Subqueries are very useful for writing SELECT statements that query values of  the unknown data. It’s a select statement embedded in a clause of another SQL  statement. It’s executed before the main query and the result is used by the main outer  query. Syntax SELECT column list FROM table name WHERE expression operator (SELECT column list FROM table WHERE condition); The operators fall into two classes - Single row:  >, < and so on - Multiple row:  IN, NOT IN Guidelines - A subquery must be enclosed in parentheses - Place the subquery after the comparison operator - Subqueries cannot contain an ORDER BY clause Exercises
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1. Select first name, last name, and title for employees who work in the same  department as Yelena select * from employees where departmentID = (select departmentID                         from employees                      
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

Subqueries - Subqueries

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online