Database Reference
In-Depth Information
We can modify this so that it will only extract the id of these rows as follows:
SELECT id
FROM
webpage
WHERE
title LIKE “Home%”
This will produce a value set of (1, 5, 7). To extract all of the log entries using this value
set we can use the following:
SELECT *
FROM
log
WHERE
webpageid IN (1,2,7)
However, in the above we are hard coding the value set that we are searching for. We are
manually entering the values that we got for the first query into the second. If we were to
change the value that we are searching for within the first query, then the value set returned
may differ, and the results in the second query will be invalid unless we re-write the second
query with the new values.
To automate the passing of values between these queries, we use the output of one query
as a subquery in another query as follows:
SELECT *
FROM
log
WHERE
webpageid IN (SELECT id FROM webpage WHERE title LIKE “Home%”)
The subquery must be contained in brackets and must return values that can be used by
the parent query.
Search WWH ::




Custom Search