Example of using a subquery

To find the books that have the same price as Straight Talk About Computers, first find the price of Straight Talk:

select price 
from titles 
where title = "Straight Talk About Computers" 
price 
------------- 
       $19.99 
 
(1 row affected)

Use the results of the first query in a second query to find all the books that cost the same as Straight Talk:

select title, price 
from titles 
where price = $19.99 
title                                         price 
------------------------------------------    -----
The Busy Executive’s Database Guide           19.99 
Straight Talk About Computers                 19.99 
Silicon Valley Gastronomic Treats             19.99 
Prolonged Data Deprivation: Four Case Studies  19.99 

You can use a subquery to receive the same results in only one step:

select title, price 
from titles 
where price = 
   (select price 
    from titles 
    where title = "Straight Talk About Computers") 
title                                         price
---------------------------------------       -----
The Busy Executive’s Database Guide           19.99 
Straight Talk About Computers                 19.99 
Silicon Valley Gastronomic Treats             19.99 
Prolonged Data Deprivation: Four Case Studies  19.99