RelationalDBDesign
RedhatLinuxSys Seomining
prev next prev next
Course navigation
Lesson 8Sub-SELECT statements The EQUALS clause
Objective EQUALS clause and how it works as sub-SELECT statement.
Earlier, we mentioned there are two different approaches to SELECT and sub-SELECT statements. The first approach is the IN clause, which we have already covered. The second is the EQUALS clause, indicated quite simply with the = sign. The syntax for the two clauses is nearly identical, with the = sign substituted for the IN phrase:
Example of a Sub-SELECT
SELECT Title FROM Titles
WHERE pub_id=
(SELECT Pub_ID FROM Publishers 
WHERE State='CA')
There is one requirement if you use this approach. Make sure the sub-SELECT statement returns only one value.
With the IN clause, you returned a list of values used as a comparison. With the EQUALS approach, there can be one and only one value represented when the results of the sub-SELECT are evaluated.
The sub-SELECT statement can have nearly any additional clauses that you can put on a standard SELECT statement.
You can use WHERE, or you can use the keywords that you know or will learn about in this course.
In the next lesson, the details about using the DISTINCT keyword and how you can integrate it into your SELECT (and sub-SELECT) statements will be discussed.
Course navigation