In this chapter, you'll look for the first time at ways that you can combine several SELECT statements in a single query. The first topic discussed is the use of subqueries. Put simply, a subquery is a query that's embedded in some way inside another query.
For example, in Chapter 2, "Retrieving Data with SQL," you saw how you can check whether a value is in a certain set using the IN keyword. You can use the same syntax but extract the values from a SQL query rather than hard-coding them:
SELECT Name FROM Student WHERE StudentID IN ( SELECT StudentID FROM StudentExam WHERE ExamID = 1);
This returns the names of all the students who took a particular exam and is just one of many examples of using subqueries that you'll investigate in this chapter.
The latter half of the chapter discusses how to combine SQL queries using a variety of set operators, such as the UNION operator. You use these operators when you want to compare data from different tables that are similar in structure but that contain different data.